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.