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

时间:2016-01-04 16:25:48

标签: javascript mongodb meteor meteor-autoform meteor-collection2

我正在尝试扩展Meteor.users集合,到目前为止,我已经完成了一切相当好的工作,除非出于某些原因,它不再允许我注册新用户。我使用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)

谁能看到我在哪里出错了?我已经玩了很长一段时间了,似乎无法让它发挥作用。非常感谢任何帮助/见解。

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'])); 
    },
});

1 个答案:

答案 0 :(得分:0)

您的标准'新'用户对象与您的架构不匹配,并且在创建时将失败。

因此,为了解决这个问题,您需要重新格式化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;
})