Hi,
I’m just starting out with Meteor.js. I have a small app running locally. I’m creating a user wth
Accounts.createUser({email:Data.email,password:Data.password}, (err) => {
if(err){
this.setState({
error: err.reason
});
}else {
this.props.history.push(’/’);
}
});.
In main.js on the server side, I’ve added two hooks,
Accounts.onCreateUser((options, user) => {
console.log(“hello”);
console.log(JSON.stringify(options));
AND
Accounts.validateNewUser((user) => {
console.log("validating "+user);
users.schema.validate(user);
if (user.username && user.username.length >= 3 && user.password.length >= 7) {
return true;
} else {
throw new Meteor.Error(403, ‘Username must have at least 3 characters and password 8 chars’);
}
});
validateNewUser doesn’t run, where onCreateUser runs. Any ideas? Is there any benefit to using validateNewUser?
According to the api both seem similar, and by throwing an error you can stop the account from being created.