-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Open
Description
I have a simple login page with local auth and custom callback.
When the login is successful, I redirect the user to the main page and check if (req.isAuthenticated()) is true.
50% of the time, req.isAuthenticated() returns false. It seems that the redirect is happening before the session information is updated. It didn't notice this issue when I was using the standard local auth options without custom callback.
Any idea ?
self.app.post('/login', function (req, res, next) {
passport.authenticate('local', function (err, user, info) {
if (err) {
return next(err);
}
var sanitizedEmail = validator.escape(req.body.username);
if (!user) {
req.flash('error', 'Wrong email or password');
req.flash('emailL', sanitizedEmail);
return res.redirect('/login');
}
req.logIn(user, function (err) {
if (err) {
return next(err);
}
return res.redirect('/main/');
});
})(req, res, next);
});
corysimmons, evanzhousy, mattzeunert, dxwc, sylv and 4 more
Metadata
Metadata
Assignees
Labels
No labels