Meteor Collections schema not allowing Google authentication

一笑奈何 提交于 2019-12-25 01:51:52

问题


I'm building a simple user account using MeteorJS. A user is only given the option to login/register using Google. If they are registering for the first time, users will be prompted to fill out their profile information after authenticating with their user account.

I'm using Collections2 to manage the schema for a user account and attaching it to Meteor.users, which is seen here:

var Schemas = {};


Schemas.UserProfile = new SimpleSchema({
    firstName: {
        type: String,
        regEx: /^[a-zA-Z-]{2,25}$/,
        optional: true
    },
    lastName: {
        type: String,
        regEx: /^[a-zA-Z]{2,25}$/,
        optional: true
    },
    gender: {
        type: String,
        allowedValues: ['Male', 'Female'],
        optional: true
    }
});


Schemas.User = new SimpleSchema({
    username: {
        type: String,
        regEx: /^[a-z0-9A-Z_]{3,15}$/
    },

    _id : {
        type: String
    },

    createdAt: {
        type: Date
    },
    profile: {
        type: Object
    },
    services: {
        type: Object,
        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
    //}
    // Option 2: [String] type
    // If you are sure you will never need to use role groups, then
    // you can specify [String] as the type
    roles: {
        type: [String],
        optional: true
    }
});


Meteor.users.attachSchema(Schemas.users);

When registering an account, I get the error:

Exception while invoking method 'login' Error: When the modifier option is true, validation object must have at least one operator

I'm new to Meteor and I'm not sure what this error means. I can't seem to find any documentation on the issue. I've tried modifying my Meteor.users.allow and Meteor.users.deny permissions to see if that has any effect, but it seems to be some underlying issue with the way I'm using the collections2 package.

UPDATE - RESOLVED: This one typo at the very bottom of my code was causing the error:

Where I have Meteor.users.attachSchema(Schemas.users); It should have been Meteor.users.attachSchema(Schemas.User);

Also similar to what @Ethaan posted, I should have referred my Schemas.User.profile type to profile: { type: Schemas.UserProfile }

That way, my user's profile settings will be validated based off of the UserProfile schema, rather than just being validated as an object.


回答1:


It seems like one of this options are null or dosnt exists.

createdAt,profile,username,services.

Like the error says something its getting validated but dosnt exists, for example you are trying to validate the profile object, but there is not profile object so nothing its getting on the schema.

When the modifier option is true

This part is because By default, all keys are required. Set optional: true. so to see where is the problem on the login/registrato workflow. change the option to false.

For example, change the optional on the profile field.

Schemas.User = new SimpleSchema({
    username: {
        type: String,
        regEx: /^[a-z0-9A-Z_]{3,15}$/
    },

    _id : {
        type: String
    },

    createdAt: {
        type: Date
    },
    profile: {
        type: Object,
        optional:false, // for example
    },
    services: {
        type: Object,
        blackbox: true
    }
});


来源:https://stackoverflow.com/questions/29397314/meteor-collections-schema-not-allowing-google-authentication

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!