meteor-useraccounts / flow-routing

Useraccounts packages add-on for integration with Flow Router and Blaze Layout.
https://atmospherejs.com/useraccounts/flow-routing
MIT License
72 stars 50 forks source link

Special case for validation-error #23

Closed stubailo closed 8 years ago

stubailo commented 8 years ago

In the upcoming Meteor Guide, we're working to have a standardized format for validation errors, which contain information about the type of error and the relevant field. This PR will allow me to use code like the below to validate new users:

// Ensuring every user has an email address, should be in server-side code
Accounts.validateNewUser((user) => {
  new SimpleSchema({
    _id: { type: String },
    emails: { type: Array },
    'emails.$': { type: Object },
    'emails.$.address': { type: String },
    'emails.$.verified': { type: Boolean },
    createdAt: { type: Date },
    services: { type: Object, blackbox: true }
  }).validate(user);

  // Return true to allow user creation to proceed
  return true;
});
stubailo commented 8 years ago

This is just a first pass to display something, we can do more passes to make the output nicer. It would be good to integrate with tap:i18n somehow to convert the error codes into readable text.

splendido commented 8 years ago

tnx @stubailo!