Handle reset password via email

please i need help,where am i wrong?
i am getting error on resetClient

<pre>Cannot POST /user/password-
reset/63c1bceb8d248f731c1b0286/594f62c35b65e767ae3f42e78087f167f16e192
32a93956e1b973e76c8534329</pre>

no other error.

router.post("password-reset/:userId/:token", async (req, res) => {
  try {
    const user = await User.findById({_id : new ObjectID(req.params.userId)});
    if (!user) return console.log('user')
    // res.status(400).send("invalid link or expired");
    const token = await Token.findOne({
      userId: user._id,
      token: req.params.token,
    });
    if (!token) return console.log('token has expired')
    // res.status(400).send("Invalid link or expired");
await User.findOneAndUpdate({_id : new ObjectID(req.params.userId)}, { password: req.body.password}, (err,data) => {
  if(err) console.log(err);
  console.log(data)
})
    await token.delete();
    res.send("password reset successfully.");
  } catch (error) {
    res.send("An error occurred");
    console.log(error);
  }
});

i find out.it turned out to be a simple mistake of missing / before the password-reset/:userId/:token in the route.that is why it was giving me the error.how i did find this, is that resetClient also has given me the not found error 404.so,the route is incorrect or did not much.i check it and boom.

1 Like