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

I want the user to be able to provide a link to protected content, for example. www.mysite.com/#/article1, then when another user opens this link, they will be redirected to the login page, after which they will be redirected to the same URL.

I have a one-page application that uses hash tags, but I see no way to do this with regular URLs.

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

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

+4
source share
2 answers

I have the same problem. At this time, I am using a simple session scheme for this, although this is not the best solution.

For instance:

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

and on your everyauth redirect path:

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

I slightly improved the solution described above (I can not call it a solution, because it seems to be absent 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'); }); 

Part two 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 
0
source

Source: https://habr.com/ru/post/1392081/


All Articles