Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Special case for validation-error #23

Merged

Conversation

stubailo
Copy link
Contributor

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
Copy link
Contributor Author

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.

@tmeasday tmeasday mentioned this pull request Dec 17, 2015
32 tasks
// XXX in the future, this should have a way to do i18n
field.setError(fieldError.type);
} else {
errorsWithoutField(fieldError.type);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't this be something like errorsWithoutField.push(fieldError.type) or am I missing something?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, you're right. I guess there aren't really any tests, maybe I should add some.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

...testing is still an unfortunate topic for useraccounts packages :(

splendido added a commit that referenced this pull request Dec 22, 2015
@splendido splendido merged commit 2d98f3c into meteor-useraccounts:master Dec 22, 2015
@splendido
Copy link
Member

tnx @stubailo!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants