0

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

1 に答える 1

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;
})
于 2016-01-04T22:45:02.663 に答える