In your code, you're not actually returning anything inside onCreateUser
. The inner function returns some value which then simply stands there.
Solution?
If the inner function (callToOutsideMethod
) is synchronous, which it doesn't seem to be, since it uses callbacks – but if it is, your can simply put a return statement in front of it:
return callToOutsideMethod(...
If the inner function is asynchronous, you need to backtrack a bit and, if possible, get the return value of that function before actually creating the user. If that is not possible, see below.
EDIT: Other hooks
Remember that many more hooks than onCreateUser
exist, both as part of the API and internally. Don't be afraid to look through the source files and use them to create your own solution; the inner workings of Meteor are relatively simple:
In the case of the onCreateUser
hook, it is called inside the function Accounts.insertUserDoc
, which is called by the different login services[1]. In your case, you need to be able to continue with the process inside insertUserDoc
after your asynchronous stuff is done.
The only way I see how, with the current API, is by redefining the insertUserDoc
function (may seem hazardous but similar stuff's been done before) – something along the lines of:
// Save the built-in function first
Accounts.insertUserDocFinal = Accounts.insertUserDoc;
Accounts.insertUserDoc = function (options, user) {
callToOutsideMethod(some_arguments, function (data) {
// Manipulate options and user objects?
Accounts.insertUserDocFinal(options, user);
});
};
[1] with the options and user objects that is then passed on to onCreateUser
(except they don't yet have the properties _id
and createdAt
).