node.js - Validating schema on methods not working with Simpl-Schema in Meteor -
i getting error,
exception while invoking method 'users_register' typeerror: cannot read property 'validate' of undefined when execute code,
schemas.user.validate(user); here sample schema,
schemas = {}; schemas.user = new simpleschema({ username: { type: string, regex: /^[a-z0-9a-z]{3,15}$/, optional:true }, emails: { type: array, optional: true }, "emails.$": { type: object, optional: true }, "emails.$.address": { type: string, regex: simpleschema.regex.email, optional:true }, "emails.$.verified": { type: boolean, optional:true }, roles: { type: object, optional: true }, "roles.company": { type: array, optional: true }, "roles.company.$": { type: string, optional: true }, profile: { type: object, optional:true }, "profile.first_name": { type: string, regex: /^[a-za-z]{2,25}$/, optional: true }, "profile.last_name": { type: string, regex: /^[a-za-z]{2,25}$/, optional: true }, "profile.retired":{ type:number, optional:true }, services: { type: object, optional: true, blackbox: true }, "profile.emails": { type: array, optional: true }, "profile.emails.$": { type: object, optional: true }, "profile.emails.$.user": { type: string, optional:true }, "profile.emails.$.host": { type: string, optional:true }, "profile.emails.$.port": { type: string, optional:true }, "profile.emails.$.password": { type: string, optional:true }, "profile.emails.$.status": { type: boolean, optional:true } }); how fix error? cause of error? sure user object defined , have correct properties.
anyone can me fix issue? have missing code?
here package.json part simpl-schema, "simpl-schema": "0.0.3",
in /server/main.js, added code,
import '../imports/api/users'; in users.js file, added code,
import simpleschema 'simpl-schema'; if (meteor.isserver) { meteor.publish ... schemas = {}; schemas.user ... (code above) meteor.methods... }
Comments
Post a Comment