Redirect user back to the page which requested authentication #12

simonmcmanus opened this Issue Jun 13, 2011 · 4 comments


None yet

2 participants



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:


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:


he is returned to:


but when Jane logs in from:


she should be returned to:


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.



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:

  .sendResponse( function (res, data) {
    var session = data.session;
    var redirectTo = session.redirectTo;
    delete session.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());
@bnoguchi bnoguchi closed this Jun 15, 2011

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


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.



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