m0atz m0atz - 1 year ago 109
Javascript Question

Do I need to put createUser code in a meteor method?

I'm writing a meteor app and working on my user registration template.

Currently I have the following code, imported on the client:

'submit form': function(event){
let username = $('[id=input-username').val();
let email = $('[id=input-email]').val();
let password = $('[id=input-password]').val();
username: username,
email: email,
password: password
}, function(error){
Bert.alert( "That username or email is either taken or invalid. Try again.", 'danger', 'growl-top-right' );
// console.log(error.reason);
else {

My question is, is it ok to have the Accounts.createUser code on the client or do I need to call this from a meteor method imported on the server? In my head I'm thinking a user can register as many times as they like with different emails / usernames therefore what's the harm in having the code on the client vs making a call to the server.

Thoughts welcome.

Answer Source

CreateUser is designed to be used from the client. It handles the encryption of the password before it is sent to the server.