andy t
andy t

Reputation: 3767

everyauth.twitter.redirectPath('/'); - change based on original page URL

I want a user to be able to share a link to secure content eg. www.mysite.com/#/article1, then when another user opens this link, they get redirected to the login page, then on complete they get redirected to the same URL.

I have a single page app so using hash tags, but I don't see any way to do this with normal URLs either.

Currently .redirectPath('/') has to be a string so I cannot make it a function that returns a string, also it does not have access to req.url so not sure how I would be able to dynamically get that value.

This is not a twitter specific issue, it is the same with all the oAuth logins I believe.

Upvotes: 4

Views: 420

Answers (2)

dearwish
dearwish

Reputation: 181

I slightly improved the above workaround (can't call it a solution as it seems as lack of feature in everyauth):

The first part remains the same:

app.get('/login/facebook', function(req, res) {
    req.session.redirect = req.header('referer');
    res.redirect('/auth/facebook');
});

The second part moved to: everyauth.facebook.findOrCreateUser:

findOrCreateUser(function(session, accessToken, accessTokenExtra, facebookUser){
    var promise = this.Promise();

    // your logic of finding or creating the user here

    if (session.redirect) { // just before the return
        this.redirectPath(session.redirect); // dynamic path
        delete session.redirect;
    }
    return promise;
}).
redirectPath('/'). // static path

Upvotes: 0

Bruno Fuster
Bruno Fuster

Reputation: 486

I'm having the same issue. At this time I'm using a simple session schema to achieve this, although it's not the best solution.

For example:

app.get('/login/facebook', function(req, res) {
  req.session.redirect = req.header('referer');
  res.redirect('/auth/facebook');
});

and at your everyauth's redirect path:

app.get('/', function(req, res) {
  if (req.session.redirect) {    
    res.redirect(req.session.redirect);
    req.session.redirect = null;
  } else {
   res.render('index');
  }
});

Upvotes: 4

Related Questions