Merge pull request #128 from bluewave-labs/feat/password-check
ACheck for new password different than old password. Fixed typo in r…
This commit is contained in:
3 files changed
+10
-2
No files matched your search
@@ -0,0 +1,2 @@
|
|||||||
|
import { toast } from "react-toastify";
|
||||||
|
export default (message) => toast(message);
|
||||||
@@ -40,10 +40,10 @@ const SetNewPassword = () => {
|
|||||||
...form,
|
...form,
|
||||||
recoveryToken: token,
|
recoveryToken: token,
|
||||||
});
|
});
|
||||||
navigate("/new-passsword-confirmed");
|
navigate("/new-password-confirmed");
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// TODO display error (Toast?)
|
// TODO display error (Toast?)
|
||||||
alert(error);
|
alert(error.response.data.msg);
|
||||||
} finally {
|
} finally {
|
||||||
setIsLoading(false);
|
setIsLoading(false);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -131,10 +131,16 @@ const validateRecoveryToken = async (req, res) => {
|
|||||||
const resetPassword = async (req, res) => {
|
const resetPassword = async (req, res) => {
|
||||||
try {
|
try {
|
||||||
const newPassword = req.body.password;
|
const newPassword = req.body.password;
|
||||||
|
|
||||||
// Validate token again
|
// Validate token again
|
||||||
const recoveryToken = await validateRecoveryToken(req, res);
|
const recoveryToken = await validateRecoveryToken(req, res);
|
||||||
const user = await UserModel.findOne({ email: recoveryToken.email });
|
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) {
|
if (user !== null) {
|
||||||
user.password = newPassword;
|
user.password = newPassword;
|
||||||
await user.save();
|
await user.save();
|
||||||
|
|||||||
Reference in new issue
Block a user