I am working with passport.js for authentication.
I have an issue which I want to resolve:
Whenever user want to reset his password, I send an email of password reset link to him with token id.
And he can reset his password after clicking that link, but after resetting password,
I want the user being redirect to dashboard page instead of log in page.
I try to find out solution with passport.js but didn't get any luck.
Can someone give me any idea to resolve this issue?
Thank You
when the user resets the password you need to authenticate the user on user's behalf.
Code would look something like this
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);
});
Note: while using custom callback, it is applications responsibility to establish the session, see Custom Callback