everyauth icon indicating copy to clipboard operation
everyauth copied to clipboard

Login route redirection

Open outaTiME opened this issue 14 years ago • 2 comments

Hi guys,

simple question ... why everyauth show login page again when user already logged and no redirect to loginSuccessRedirect ??

scenario:

  1. user logins (logged ok)
  2. redirects to loginSuccessRedirect
  3. type in address bar the "login" url again
  4. 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 !

outaTiME avatar Apr 13 '12 19:04 outaTiME

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();
});

daviddripps avatar May 12 '12 21:05 daviddripps

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

inolasco avatar Feb 01 '16 19:02 inolasco