已将架构附加到 Meteor.users,现在无法创建新用户

Attached schema to Meteor.users and now unable to create new users

我正在尝试扩展 Meteor.users 集合,到目前为止我的一切都运行良好,除了某些原因,它不再允许我注册新用户。我正在为 login/registration 使用 accounts-google 包,使用已经创建的帐户登录效果很好,但是当我尝试使用新帐户注册时它不起作用,我收到以下信息我的浏览器控制台出现错误:

Exception in delivering result of invoking 'login': ReferenceError: ServiceConfiguration is not defined
    at http://localhost:3000/packages/useraccounts_core.js?e3a764dbf634d8bf2a393797c0a82e9fadef2e7a:2551:48
    at Accounts.callLoginMethod.userCallback (http://localhost:3000/packages/accounts-oauth.js?8a30b216f87b515ab9b4bf5d4970a7113d0c6c2f:163:7)
    at http://localhost:3000/packages/accounts-base.js?7dabd814506e384c709f8bf707377955f9814129:612:26
    at http://localhost:3000/packages/underscore.js?46eaedbdeb6e71c82af1b16f51c7da4127d6f285:794:19
    at loggedInAndDataReadyCallback (http://localhost:3000/packages/accounts-base.js?7dabd814506e384c709f8bf707377955f9814129:708:7)
    at null._callback (http://localhost:3000/packages/meteor.js?9730f4ff059088b3f7f14c0672d155218a1802d4:999:22)
    at _.extend._maybeInvokeCallback (http://localhost:3000/packages/ddp-client.js?250b63e6c919c5383a0511ee4efbf42bb70a650f:3500:12)
    at _.extend.receiveResult (http://localhost:3000/packages/ddp-client.js?250b63e6c919c5383a0511ee4efbf42bb70a650f:3520:10)
    at _.extend._livedata_result (http://localhost:3000/packages/ddp-client.js?250b63e6c919c5383a0511ee4efbf42bb70a650f:4625:9)
    at onMessage (http://localhost:3000/packages/ddp-client.js?250b63e6c919c5383a0511ee4efbf42bb70a650f:3365:12)

谁能看出我哪里出错了?我已经玩了很长时间了,但似乎无法让它工作。非常感谢任何help/insight。

Schema = {};

Schema.UserProfile = new SimpleSchema({
    userProfile: {
        type: Object
    },
    'userProfile.firstName': {
        type: String,
        optional: true,
        label: "First Name"
    },
    'userProfile.lastName': {
        type: String,
        optional: true,
        label: "Last Name"
    },
    'userProfile.birthday': {
        type: Date,
        optional: true,
        label: "Date of Birth"
    },
    'userProfile.contactEmail': {
        type: String,
        optional: true,
        label: "Contact Email"
    },      
    'userProfile.gender': {
        type: String,
        allowedValues: ['Male', 'Female'],
        optional: true,
        label: "Gender"
    },
    'userProfile.country': {
        type: String,
        optional: true,
        label: "Country"
    },
    'userProfile.address': {
        type: String,
        optional: true,
        label: "Address"
    },
    'userProfile.city': {
        type: String,
        optional: true,
        label: "City"
    },
    'userProfile.stateProvince': {
        type: String,
        optional: true,
        label: "State/Province"
    },
    'userProfile.postalCode': {
        type: String,
        optional: true,
        label: "Postal Code"
    },
    'userProfile.phoneNumber': {
        type: String,
        optional: true,
        label: "Phone Number"
    },    

});

Schema.User = new SimpleSchema({
    username: {
        type: String,
        // For accounts-password, either emails or username is required, but not both. It is OK to make this
        // optional here because the accounts-password package does its own validation.
        // Third-party login packages may not require either. Adjust this schema as necessary for your usage.
        optional: true
    },
    emails: {
        type: Array,
        // For accounts-password, either emails or username is required, but not both. It is OK to make this
        // optional here because the accounts-password package does its own validation.
        // Third-party login packages may not require either. Adjust this schema as necessary for your usage.
        optional: true
    },
    "emails.$": {
        type: Object
    },
    "emails.$.address": {
        type: String,
        regEx: SimpleSchema.RegEx.Email
    },
    "emails.$.verified": {
        type: Boolean
    },
    createdAt: {
        type: Date
    },
    profile: {
        type: Schema.UserProfile,
        optional: true
    },
    // Make sure this services field is in your schema if you're using any of the accounts packages
    services: {
        type: Object,
        optional: true,
        blackbox: true
    },
    // Add `roles` to your schema if you use the meteor-roles package.
    // Option 1: Object type
    // If you specify that type as Object, you must also specify the
    // `Roles.GLOBAL_GROUP` group whenever you add a user to a role.
    // Example:
    // Roles.addUsersToRoles(userId, ["admin"], Roles.GLOBAL_GROUP);
    // You can't mix and match adding with and without a group since
    // you will fail validation in some cases.
    roles: {
        type: Object,
        optional: true,
        blackbox: true
    },
    // In order to avoid an 'Exception in setInterval callback' from Meteor
    heartbeat: {
        type: Date,
        optional: true
    }
});

Meteor.users.attachSchema(Schema.User);

Meteor.users.allow({
    insert: function(userId, doc) {
        // only allow posting if you are logged in
        console.log("doc: " + doc + " userId: " + userId);
        return !! userId;
    },

    update: function(userId, doc, fieldNames) {
        // only allow updating if you are logged in
        console.log("doc: " + doc + " userId: " + userId);
        // a user can only update his own user doc and only the 'userProfile' field
        return !! userId && userId === doc._id && _.isEmpty(_.difference(fieldNames, ['userProfile'])); 
    },
});

您的标准 'new' 用户对象与您的架构不匹配,创建失败。

因此,要解决此问题,您需要重新格式化 Account.onCreateUser 函数提供的对象的输出:

Accounts.onCreateUser(function (options, user) {
    //format the 'user' object as you need it to be here
    // to pass your schema validation
    return user;
})