Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update password not hashed during profile update. #10

Open
aayushkuntal opened this issue Apr 30, 2023 · 1 comment
Open

Update password not hashed during profile update. #10

aayushkuntal opened this issue Apr 30, 2023 · 1 comment

Comments

@aayushkuntal
Copy link

aayushkuntal commented Apr 30, 2023

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');
    }
});
@shivansh84ya
Copy link

Could you please assign this issue to me?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants