I've been troubleshooting the following code snippet:
router.post('/register', function(req, res) {
User.register(new User({ username : req.body.username }),
req.body.password, function(err, user) {
if (err) {
return res.status(500).json({err: err});
}
if(req.body.firstname) {
user.firstname = req.body.firstname;
}
if(req.body.lastname) {
user.lastname = req.body.lastname;
}
user.save( function(err, user) {
passport.authenticate('local')(req, res, function () {
return res.status(200).json({status: 'Registration Successful!'});
});
});
});
});
The output of this code is:
{
"_id" : ObjectId("59a631ff29e0a506c81032b3"),
"salt" : null,
"hash" : null,
"username" : "admin",
"admin" : false,
"lastname" : "Last",
"firstname" : "Test",
"__v" : 0
}
The salt and hash values are generated by the passport.authenticate('local') function. If I remove the user.save(function(err, user) {...}); code block around the passport.authenticate, it does not update the lastname or firstname fields, but the salt and hash values do get updated.
I've explored this forum, Passport (), and Passport-local github (https://github.com/jaredhanson/passport-local) for possible solutions, but haven't come across a similar issue or resolution.
If anyone has suggestions, I would greatly appreciate it.