I have a Meteor application and am trying to register a user and assign a role:
In the client registration file, I have a user with email, password, username, profile (firstname and lastname) and role:
Accounts.createUser(user, user.roles, function(error){
if(!error) {
FlowRouter.go('home');
console.log("Registration successful");
}
else {
FlashMessages.sendError(error.reason);
console.log("Registration not successful: " + error.reason);
}
});
And then in the server file I have:
Accounts.onCreateUser(function(options, user) {
if(options.roles) {
user.roles = options.roles;
Roles.addUsersToRoles(user._id, user.roles);
}
return user;
});
With this code, I always get an error message:
Exception in delivering result of invoking 'createUser': TypeError: options.userCallback.apply is not a function
at http://localhost:3000/packages/accounts-base.js?7dabd814506e384c709f8bf707377955f9814129:612:26
at http://localhost:3000/packages/underscore.js?46eaedbdeb6e71c82af1b16f51c7da4127d6f285:794:19
at loggedInAndDataReadyCallback (http://localhost:3000/packages/accounts-base.js?7dabd814506e384c709f8bf707377955f9814129:708:7)
at null._callback (http://localhost:3000/packages/meteor.js?9730f4ff059088b3f7f14c0672d155218a1802d4:999:22)
The user does get added successfully though!
EDIT: THE FIX
On server side:
Accounts.onCreateUser(function(options, user) {
if (options.profile) {
user.profile = options.profile;
}
if(options.roles) {
user.roles = options.roles;
Roles.addUsersToRoles(user._id, user.roles);
}
return user;
});
On client side:
Accounts.createUser(user, function(error){
if(!error) {
FlowRouter.go('home');
}
else {
FlashMessages.sendError(error.reason);
}
});