自定义returnURL没有传递给Node.js Passport

时间:2014-10-10 15:28:28

标签: javascript node.js passport.js url-parameters

从第二个答案: Custom returnUrl on Node.js Passport's Google strategy

我正在使用从前端传递的自定义网址,如:

  <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,因此它不会重定向到指定的重定向网址,如何正确传递网址?

1 个答案:

答案 0 :(得分:0)

我修复了它,必须将URL中的/ s传递为:

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