Login route redirection
Hi guys,
simple question ... why everyauth show login page again when user already logged and no redirect to loginSuccessRedirect ??
scenario:
- user logins (logged ok)
- redirects to loginSuccessRedirect
- type in address bar the "login" url again
- and login page shows (at this point everyauth will be redirect to loginSuccessRedirect and no display login page again)
how to solve that, its possible, any ideas ??
thks !
I'll add this to everyauth and send a pull request, but for now I just add the following right before app.use(everyauth.middleware()); You may need to update it a bit to reflect your app structure though. My register and login endpoints are just "/register" and "/login". The redirected url is "/user". Let me know if anything there doesn't make sense.
app.use(function(req, res, next) {
if(req.url.match(/\/(login|register)/) && req.session && req.session.user)
res.redirect('/user');
else
next();
});
This is old, but I have this issue and had to solve it with this, based on the answer by @daviddripps:
app.use('/login', function(req, res, next) {
if (req.session && req.session.auth && req.session.auth.loggedIn && req.session.auth.userId) {
return res.redirect('/main');
}
return next();
});
This is only for /login, but the same could be done for registration