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

@@ -0,0 +1,2 @@
import { toast } from "react-toastify";
export default (message) => toast(message);
+2 -2
View File
@@ -40,10 +40,10 @@ const SetNewPassword = () => {
...form,
recoveryToken: token,
});
navigate("/new-passsword-confirmed");
navigate("/new-password-confirmed");
} catch (error) {
// TODO display error (Toast?)
alert(error);
alert(error.response.data.msg);
} finally {
setIsLoading(false);
}
+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();