-
Notifications
You must be signed in to change notification settings - Fork 571
Open
Description
The password is not getting hased before the update in the updateUserProfile function of userController.js.
It causes the user to update the password but cant login again.
- Updated Code
const user = await User.findById(req.user._id);
if(user){
user.name=req.body.name||user.name;
user.email=req.body.email||user.email;
if(req.body.password){
const hashedPassword=await bcrypt.hash(req.body.password,10);
user.password=hashedPassword;
}
const updatedUser=await user.save();
res.json({
_id: updatedUser._id,
name: updatedUser.name,
email: updatedUser.email,
isAdmin: updatedUser.isAdmin,
pic: updatedUser.pic,
token: generateToken(updatedUser._id)
})
}else{
res.status(404);
throw new Error('User not found');
}
});
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels