如何在Node.js中重置密码后使用passport.jslogin?

我正在使用passport.js进行身份validation。

我有一个问题,我想解决:

每当用户想要reset他的password ,我发送password reset link的电子邮件与token id他。

点击该链接后,他可以reset password ,但重置密码后,

我希望用户被redirect到dashboard page而不是log in page

我尝试用passport.js找出解决scheme,但没有得到任何好运。

有人可以给我任何想法来解决这个问题?

谢谢

当用户重置密码时,您需要代表用户对用户进行身份validation。

代码看起来像这样

 app.post('/resetpassword', function(req, res, next) { /* code to reset the password */ // append username and new password to req.body // assuming passport still uses username and password as field indicator req.body.username= "user_name"; req.body.password= "user_new_password"; passport.authenticate('local', function(err, user, info) { if (err) { return next(err); } if (!user) { return res.sendStatus(401); } // it is your responsibility to establish the session req.logIn(user, function(err) { if (err) { return next(err); } return res.rediect("to_users_dashboard_path"); }); })(req, res, next); }); 

注意:在使用自定义callback时,应用程序负责build立会话,请参阅自定义callback