Skip to content

Update password not hashed during profile update. #10

@aayushkuntal

Description

@aayushkuntal

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');
    }
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions