Horje
update password using comparePassword() Method Code Example
update password using comparePassword() Method
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.');
    }




Javascript

Related
discord.js find word inside comment Code Example discord.js find word inside comment Code Example
How to Subtract the numbers in the array, starting from the right in javascript Code Example How to Subtract the numbers in the array, starting from the right in javascript Code Example
how to connect mongoose database with nodejs Code Example how to connect mongoose database with nodejs Code Example
react native make safe view in mobile Code Example react native make safe view in mobile Code Example
dinamically add checked to checkbox Code Example dinamically add checked to checkbox Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
8