Redirect user back to the page which requested authentication #12

Closed
simonmcmanus opened this Issue Jun 13, 2011 · 4 comments

Projects

None yet

2 participants

@simonmcmanus

Hi,

Everyauth is working quite nicely for me now. The one bit of functionality that I cannot figure out is how to redirect the user back to the page from which they requested login.

I know I can change the redirect value:

.redirectPath('/HARDCODED/PATH');

But that will change it for every request. I very specifically want to redirect the user back to their originating page:

So when Bob clicks login from:

/page1/blah

he is returned to:

/page1/blah

but when Jane logs in from:

/page2/blah

she should be returned to:

/page2/blah

after login.

I guess I could do this with a cookie but just thought I would check if everyauth has this capability built in.

Thanks for all the work. Everyauth looks like a really nice auth module.

Simon

@bnoguchi
Owner

I haven't yet added a nice sugary way to do this.

Until then, you can accomplish this by (a) saving the original uri to your session and then (b) configuring the sendResponse step. For example, to do this for all oauth2 based modules:

everyauth.oauth2
  .sendResponse( function (res, data) {
    var session = data.session;
    var redirectTo = session.redirectTo;
    delete session.redirectTo;
    res.redirect(redirectTo);
  });

app.get('/some/path/requiring/login', function (req, res) {
  if (! req.loggedIn) {
    req.session.redirectTo = '/some/path/requiring/login';
    return res.redirect(everyauth.facebook.entryPath());
  }
  res.render('someView');
});
@bnoguchi bnoguchi closed this Jun 15, 2011
@bnoguchi
Owner

Make sure to upgrade everyauth to the latest version 0.2.9, so you can have access to the data argument of sendResponse.

@simonmcmanus

Thanks for the help.

This appears to be working. EveryAuth is doing exactly what I needed from an auth module. Good stuff. I'm impressed.

Some sugar would be lovely, but for the time being things are working which is the main thing.

Thanks for you help. Really appreciated.

Simon

@bnoguchi
Owner

For those of you who would like to do this with the password module, see GH-41.

@fxwalsh fxwalsh added a commit to fxwalsh/social-example that referenced this issue Apr 8, 2014
@fxwalsh fxwalsh Added fix for Facebook redirect issue 323b382
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment