Dear Community,
I am trying to put in place a verification process for new users on account creation. As such I am using the Accounts.validateNewUser function. I manage to put it in place and make it throw errors (it even prevents creating accounts) BUT even when I throw an error it then calls Accounts.validateLoginAttempt which also throws a different error that is visible. Problem is I’d like to see the first error. Let me show you with code:
I exaggerated the code to show you the error :
Accounts.validateNewUser((user) => {
throw new Meteor.Error("NO REGISTRATION ALLOWED");
}
Accounts.validateLoginAttempt(function(options){
if (!options.user){
throw new Meteor.Error("Invalid Email or Password");
}
})
In this case I think I should get the first error (no registration allowed) as soon as someone would try to sign up but NO, I get the second one. Even though the account is not created. So validateNewUser is making the job of blocking the user creation but still continuing the Login process. Therefor I never manage to get the first error on client side :
Accounts.createUser({email, password, username}, (err) => {
if (err) {
console.log(err);
this.setState({
error: err.reason || err.error
})
} else {
Meteor.call('sendVerificationLink', (error, response) => {
if(err){
this.setState({
error: err.reason || err.error
})
} else {
this.setState({
error: ""
})
}
});
}
});
Any idea why or how to solve this ?