ACheck for new password different than old password. Fixed typo in route. Updated error msg

This commit is contained in:
Alex Holliday committed 2024-06-12 10:25:35 -07:00
1 parent 6457f9f1ac
commit 80af000a0c
3 files changed
+10 -2

No files matched your search

+6
View File
@@ -131,10 +131,16 @@ const validateRecoveryToken = async (req, res) => {
const resetPassword = async (req, res) => {
try {
const newPassword = req.body.password;
// Validate token again
const recoveryToken = await validateRecoveryToken(req, res);
const user = await UserModel.findOne({ email: recoveryToken.email });
const match = await user.comparePassword(newPassword);
if (match === true) {
throw new Error("New password must be different from old password");
}
if (user !== null) {
user.password = newPassword;
await user.save();