1
votes

I create a new user using the {{>loginButtons}} template and accounts-password, and am successfully logged in, but when I log out and attempt to log back in with the password that I'd set, I get the "User has no password set" error.

I have the following code in accountsServer.js in my server folder:

Accounts.onCreateUser(function (user, options) {
  someCollection.insert({
    name: user.username,
    elo: 1500,
  });
  return user;
});

And I have set up a USERNAME_ONLY config option in accountsClient.js in my client folder:

Accounts.ui.config({
    passwordSignupFields: "USERNAME_ONLY"
});

Can anybody help me out? When I comment out the code entirely in the Accounts.onCreateUser() function, the error goes away, so I'm thinking this is the root of the problem but I'm not sure what's causing it.

1

1 Answers

1
votes

Maybe it's due to this:

The default create user function simply copies options.profile into the new user document. Calling onCreateUser overrides the default hook. This can only be called once.

Therefore, your user creation no longer copies the options in your user before registering it. Also, your arguments options and user seem inverted!!

You could just add this logic back this way:

Accounts.onCreateUser(function (options, user) {
  someCollection.insert({
    name: user.username,
    elo: 1500,
  });
  if (options.profile)
    user.profile = options.profile;
  return user;
});