diff --git a/Client/src/Components/Notifications/notify.js b/Client/src/Components/Notifications/notify.js new file mode 100644 index 000000000..86be4a0ab --- /dev/null +++ b/Client/src/Components/Notifications/notify.js @@ -0,0 +1,2 @@ +import { toast } from "react-toastify"; +export default (message) => toast(message); diff --git a/Client/src/Pages/SetNewPassword/index.jsx b/Client/src/Pages/SetNewPassword/index.jsx index 3da1c4f3e..d2360c7c5 100644 --- a/Client/src/Pages/SetNewPassword/index.jsx +++ b/Client/src/Pages/SetNewPassword/index.jsx @@ -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); } diff --git a/Server/db/MongoDB.js b/Server/db/MongoDB.js index 0e379b687..07804589e 100644 --- a/Server/db/MongoDB.js +++ b/Server/db/MongoDB.js @@ -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();