Mettre à jour le mot de passe à l'aide de la méthode comparepassword ()

router.put('/password',verifyToken,UserController.updatePassword);


async updatePassword(req, res) {
        const { user } = req;
        const { currentPassword, newPassword } = req.body;

        const matched = await user.comparePassword(currentPassword);
        if (!matched) {
            return res.warn('', req.__('PASSWORD_MATCH_FAILURE'));
        }
        const matcheAddedPassword = await user.comparePassword(newPassword);
        if(matcheAddedPassword){
            return res.warn('','Old password and new passowrd can not be same');
        }


        user.password = newPassword;
        await user.save();

        return res.success('', 'Password updated successfully.');
    }
Angry Albatross