Handle reset password via email

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

<pre>Cannot POST /user/password-

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);
    await token.delete();
    res.send("password reset successfully.");
  } catch (error) {
    res.send("An error occurred");

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