Below is my code, but for some reason the first and last names aren't saved? How do I save additional info when creating a new user in Meteor? I'm using the accounts-password package.
Accounts.createUser({
email: email,
password : password,
profile: {firstName: firstName, lastName: lastName}
}, function (err) {
if (err) {
// Inform the user that account creation failed
} else {
// Success. Account has been created and the user
// has logged in successfully.
}
});
The onCreateUser
callback should return the finall user
object which is about to be saved into the database. The problem you have comes from the fact that the profile
data need to be hooked manually tho the user
object (see meteor docs for more details):
Accounts.onCreateUser(function(options, user) {
// [...]
if (options.profile)
user.profile = options.profile;
return user;
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.