2014-10-10 40 views
0

从第二个答案在这里: Custom returnUrl on Node.js Passport's Google strategy定制RETURNURL不传递给Node.js的护照

我使用的是从前端通过使用自定义的网址:

<a href="/auth/meetup?redirect=/chat/{{currentChatID}}" class="btn btn-meetup"><span class="fa fa-meetup"></span> Meetup</a> 

redirect参数例如:?redirect=/chat/room1

而且在护照:

app.get('/auth/meetup', function(req, res, next) { 
     req.session.redirect = req.query.redirect; 
     next(); 
    }, passport.authenticate('meetup')); 


    app.get('/auth/meetup/callback', passport.authenticate('meetup', { 
     failureRedirect: '/' 
    }), function (req, res) { 
     res.redirect(req.session.redirect || '/profile/worlds/meetup'); 
     delete req.session.redirect; 
    }); 

req.query.redirect参数是undefined所以它不会重定向到指定的重定向URL,我该如何正确地传递URL?

回答

0

我固定它,只好在URL通过/ S为:

href="/auth/meetup?redirect=%2Fchat%2F{{currentChatID}}"