DEV Community

Discussion on: How to Handle Password Reset in ExpressJS

Collapse
 
mtrcn profile image
Mete Ercan Pakdil

Hi Kelvin, great article, thanks. I just spotted that you forgot to check whether reset token is valid or not in '/reset-confirm/:token' Post method.

const passwordReset = await PasswordReset.findOne({ token })
Enter fullscreen mode Exit fullscreen mode

passwordReset is not being checked after this line.

Collapse
 
kelvinvmwinuka profile image
Kelvin Mwinuka

Hi Mete,

Good eye. If we don't check it here, the user update will throw an error. To avoid this we can add a guard clause to check the password reset object:

if (!passwordReset) {
    return res.status(404).send()
}

// Continue with the reset
Enter fullscreen mode Exit fullscreen mode