onCreateUser - Not Saving the User


#1

I am using ian:accounts-ui-bootstrap-3 and accounts-password and for whatever reason I can’t get my user’s email and password to save.

So here is the code:

Accounts.onCreateUser(function(options, user) {
  options.roles = ['user'];
  user = {
    profile: options.profile,
    roles: options.roles
  }
  return user;
});

The user is saved with the profile and roles correctly assigned; however, my email and password are gone…In addition, when I try to login again it says that the user cannot be found on the database. Any help is greatly appreciated.


#2

I believe you need to add both the email and password to the object you return. Check the function parameters to see if you can find this information and put it in the object you’re returning.


#3

in other words, instead of

user = {
profile: options.profile,
roles: options.roles
}

try

user.profile = options.profile;
user.roles = options.roles;

edit: you are inadvertently overriding the default behavior of the ‘user’ parameter by assigning it to another object. Just add the additional information to the already existing object.


#4

Hi, try this.

user = _.extend(user,{profile : options.profile, roles : option.roles});