自定义returnURL不传递到节点。js的护照

时间:2022-02-12 10:35:45

From the second answer here: Custom returnUrl on Node.js Passport's Google strategy

从这里的第二个答案:在节点上自定义returnUrl。js的护照是谷歌的策略

I'm using a custom URL passed from the front-end like:

我正在使用一个从前端传递的自定义URL:

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

Where the redirect parameter is, for example: ?redirect=/chat/room1

例如,重定向参数在哪里:?重定向=/chat/room1 ?

And in Passport:

和护照:

    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;
    });

The req.query.redirect parameter is undefined so it won't redirect to the specified redirect URL, how do I pass the URL correctly?

req.query。重定向参数未定义,因此不会重定向到指定的重定向URL,如何正确传递URL ?

1 个解决方案

#1


0  

I fixed it, had to pass the /s in the URL as:

我修正了它,必须通过URL中的/s:

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

#1


0  

I fixed it, had to pass the /s in the URL as:

我修正了它,必须通过URL中的/s:

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