小编Bur*_*ive的帖子

async / await doesn't seem to work nodejs passport reset passwd

For some reason i get this Error :

错误:req#login 需要在 Exports.update (/home/project) 处的 IncomingMessage.req.login.req.logIn (/home/project/node_modules/passport/lib/http/request.js:47:44) 处使用回调函数/controllers/authController.js:92:13) 在 process.internalTickCallback (internal/process/next_tick.js:77:7)

用这个代码:

exports.update = async (req, res) => {
  const user = await User.findOne({
  resetPasswordToken: req.params.token,
  resetPasswordExpires: { $gt: Date.now() }
  });

  if (!user) {
    req.flash('error', 'Password reset is invalid or has expired');
    return res.redirect('/login');
  }

  const setPassword = promisify(user.setPassword, user);
  await setPassword(req.body.password);
  user.resetPasswordToken = undefined;
  user.resetPasswordExpires = undefined;
  const updatedUser = await user.save();
  await req.login(updatedUser);
  req.flash('success', 'Your password has been reset! …
Run Code Online (Sandbox Code Playgroud)

node.js express passport.js

2
推荐指数
1
解决办法
1561
查看次数

标签 统计

express ×1

node.js ×1

passport.js ×1