piyush-eon / notezipper

Watch Full Tutorial for this App on YouTube
https://www.youtube.com/watch?v=IQXjO0t4XRM&list=PLKhlp2qtUcSYC7EffnHzD-Ws2xG-j3aYo
142 stars 574 forks source link

Update password not hashed during profile update. #10

Open aayushkuntal opened 1 year ago

aayushkuntal commented 1 year ago

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.

    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 commented 4 months ago

Could you please assign this issue to me?