Reputation: 7343
I need to create new user when I recived message from rabbitmq. But Accounts.createUser doesn't work outside methods even if I wrap it with Meteor.bindEnvironment. But for example IronRouter works well when I call createUser. How I can create new users outside of Meteor methods or client?
var newUserCreate = Meteor.bindEnvironment(function(msg){
var email, username = msg.data.email;
var password = msg.data.password;
Accounts.createUser({username: username, email: email, password: password});
}, function(e){throw e;})
And just call newUserCreate(msg)
Upvotes: 1
Views: 493
Reputation: 19544
When you write
var a, b = 42;
Then b
is equal to 42
, but a
stays undefined
. My guess is that the method fails because you pass email: undefined
in params. So try to rewrite it and see what happens:
var newUserCreate = Meteor.bindEnvironment(function(msg) {
var email = msg.data.email;
var username = msg.data.email;
var password = msg.data.password;
var result = Accounts.createUser({username: username, email: email, password: password});
console.log("RESULT", result);
}, function(e){
throw e;
});
Upvotes: 2
Reputation: 75955
It should 'just work'. Remember don't pass a callback on the server it wont fire. You have to instead look for what it returns. Fibers will make sure meteor waits until the user is created before the next statement is run. What is returned is the new user's _id
.
e.g
var result = Account.createUser(params);
Upvotes: 1