Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to validate user creation on the server in Meteor

What is the best approach to validate user creation on the client and server?

I've tried to validate user creation both server and client side. First I've used methods and Accounts.createUser function but it didn't work even that the documentation says it should.

I've tried different approach. I used Accounts.createUser to validate it on the client and Account.onCreateUser on the server. The problem is that I can't validate password because it's encrypted.

So what is the best way to do it?

like image 769
Łukasz Jagodziński Avatar asked Oct 19 '25 15:10

Łukasz Jagodziński


1 Answers

For validation of new users, see here

Example from the docs:

// Validate username, sending a specific error message on failure.
Accounts.validateNewUser(function (user) {
    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";
});
like image 73
user2602152 Avatar answered Oct 21 '25 05:10

user2602152