Created
October 21, 2022 08:06
-
-
Save Octagon-simon/1225f1a30c992dad5e957b8af53b7cc7 to your computer and use it in GitHub Desktop.
Revisions
-
Octagon-simon created this gist
Oct 21, 2022 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,28 @@ 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" }) } })