Meteor Collections Schema Not Allowing Google Authentication

I am creating a simple user account using MeteorJS. The user is given the option to login / register using Google. If they are registering for the first time, users will be prompted to fill in their profile information after authenticating with their user account.

I'm using Collections2 to manage the schema for a user account and attach it to Meteor.users, which is visible 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 an error:

Exception when calling method 'login' Error: when the modifier parameter is true, the validation object must have at least one statement

I'm new to Meteor and I'm not sure what this error means. I can't seem to find any documentation on this. I've tried modifying the permissions of Meteor.users.allow and Meteor.users.deny to see if it has any effect, but this seems to be one of the main problems with the way I use the collections2 package.

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

Where Meteor.users.attachSchema(Schemas.users);

should I have itMeteor.users.attachSchema(Schemas.User);

Also similar to what @Ethaan posted, I had to specify my Schemas.User.profile type to profile: { type: Schemas.UserProfile }

This way, my user profile settings will be validated based on the UserProfile schema and not just validated as an object.

0


source to share


1 answer


One of these seems to be null or dosnt.

createdAt,profile,username,services.

      

Like the error says something about confirming it, but dosnt exists, for example you are trying to check a profile object but there is no profile object, so nothing happens in the schema.

If modifier option is true



This part is that all keys are required by default. Install optional: true

. so to see where the problem is in the login / registrato workflow. change the parameter to false

.

For example, change the option in 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
    }
});

      

+2


source







All Articles