Reputation: 2065
I'm using the collection2 package as seen here: https://github.com/aldeed/meteor-collection2
I've set up a simple schema wherein only email
is a non-optional value, but despite this simpleness the validation fails every time claiming that "Email is required".
My schema:
Schema.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
},
birthday: {
type: Date,
optional: true
},
likes: {
type: [String],
optional: true
}
})
Schema.User = new SimpleSchema({
username: {
type: String,
regEx: /^[a-z0-9A-Z_]{3,15}$/,
optional: true
},
email: {
type: String,
regEx: SimpleSchema.RegEx.Email
},
verified: {
type: Boolean,
optional: true
},
createdAt: {
type: Date,
optional: true
},
profile: {
type: Schema.UserProfile,
optional: true
},
services: {
type: Object,
optional: true,
blackbox: true
}
})
I set it like so:
Meteor.users.attachSchema(Schema.User)
And just to check it I hardcode a value to add a user with a perfectly fine email address:
Accounts.createUser({email: "[email protected]"})
But when I run this a big exception is returned, saying, among other things:
Exception while invoking method 'registerUser` Error: Email is required
at getErrorObject
<packages/aldeed:collection2/collection2.js:369:1>
Sanitized and reported to the client as: Email is required [400]
What am I missing?
Upvotes: 2
Views: 915
Reputation: 2386
As you can see in the docs, user.emails
is an an array of objects with the properties verified
and address
.
So try something like this instead:
emails: {
type: [Object],
optional: true
},
'emails.$.address': {
type: String,
regEx: SimpleSchema.RegEx.Email
},
'emails.$.verified': {
type: Boolean
},
Upvotes: 5