Created
October 21, 2022 08:06
-
-
Save Octagon-simon/1225f1a30c992dad5e957b8af53b7cc7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
app.post('/reset', async (req, res) => { | |
try{ | |
//find a document with such email address | |
const user = await User.findOne({email : req.body.email}) | |
//check if user object is not empty | |
if(user){ | |
//generate hash | |
const hash = new User(user).generatePasswordResetHash() | |
//generate a password reset link | |
const resetLink = `http://localhost:5000/reset?email=${user.email}?&hash=${hash}` | |
//return reset link | |
return res.status(200).json({ | |
resetLink | |
}) | |
//remember to send a mail to the user | |
}else{ | |
//respond with an invalid email | |
return res.status(400).json({ | |
message : "Email Address is invalid" | |
}) | |
} | |
}catch(err){ | |
console.log(err) | |
return res.status(500).json({ | |
message : "Internal server error" | |
}) | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment