From b0f4db8d0f616e2d31af8cb2ce19c2adbd28028e Mon Sep 17 00:00:00 2001 From: David Glasser Date: Mon, 15 Oct 2012 17:35:07 -0700 Subject: [PATCH] Docs for validateNewUser describe what happens on throw. --- docs/client/api.html | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/docs/client/api.html b/docs/client/api.html index 81a94b4a87..3104a614f6 100644 --- a/docs/client/api.html +++ b/docs/client/api.html @@ -1248,14 +1248,22 @@ Example: {{> api_box accounts_validateNewUser}} -This can be called multiple times. If any of the functions return -`false` the new user creation is aborted. +This can be called multiple times. If any of the functions return `false` or +throw an error, the new user creation is aborted. To set a specific error +message (which will be displayed by [`accounts-ui`](#accountsui)), throw a new +[`Meteor.Error`](#meteor_error). Example: - // All users must have a username longer than 3 characters. + // Validate username, sending a specific error message on failure. Accounts.validateNewUser(function (user) { - return user.username && user.username.length >= 3; + if (user.username && user.username.length >= 3) + return true; + throw new Meteor.Error(403, "Username must have at least 3 characters"); + }); + // Validate username, without a specific error message. + Accounts.validateNewUser(function (user) { + return user.username !== "root"; }); {{> api_box accounts_onCreateUser}}