Skip to content

Instantly share code, notes, and snippets.

@Octagon-simon
Created October 21, 2022 08:06
Show Gist options
  • Save Octagon-simon/1225f1a30c992dad5e957b8af53b7cc7 to your computer and use it in GitHub Desktop.
Save Octagon-simon/1225f1a30c992dad5e957b8af53b7cc7 to your computer and use it in GitHub Desktop.
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