I have a SignUp/SignIn Process on my meteor site. I have a form to register new users and a form to login users.
I init users on serverside
via
Accounts.createUser({username: "myusername", password: "mypassword"});
and I can login into my dummyusers via my loginform on the client
with
Meteor.loginWithPassword(username, password)
I dont know why but for some reason I can´t create new users on clientside. If I call
Accounts.createUser({username: username, password: password});
it returns undefined
(safari)
I checked the input strings (username, password) and its not generating the error even pure strings like
Accounts.createUser({username: "test", password: "pass"});
returns undefined
on client console.
I published and subscribed my users via:
Server
Meteor.publish('users', function () {
console.log("Server Log: publishing all users");
return Meteor.users.find();
});
Client
Meteor.subscribe("users");
I also can count()
users on the client console but I cant use Accounts.createUser()
so the createUser() function is not even working in my console.
Why I cant use Accounts.createUser()
on client/console
?
Accounts.createUser is an asynchronous function on the client because it needs to query the server to know if it actually succeeded (the username or email could already be in use). The return value of an asynchronous function will always be undefined
, so the result is expected.
If you start with an empty project and an empty database, you could do:
Accounts.createUser({username: 'dave', password: 'password'});
which will return undefined
, however a subsequent call to Meteor.userId()
should return a string.
In order to determine if the call succeeded, you will need to supply a callback:
Accounts.createUser({username: 'dave', password: 'password'}, function(err) {
if (err)
console.log(err);
else
console.log('success!');
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With