0

我使用护照谷歌oauth策略进行了简单的身份验证设置。它工作得很好,但有一个例外。获得回调后,它会设置一个 cookie(使用 session-cookie)并重定向到主页。但不会针对此即时重定向请求发送 cookie。如果我再次重新加载或转到任何页面,cookie 将正确发送并且我已正确登录。

这是重定向的回调代码

 router.get(
    "/google/callback",
    passport.authenticate("google", { failureRedirect: "/login" }),
    function (req, res) {
      res.redirect("/");
    }
  );

知道可能是什么原因吗???

4

1 回答 1

0

根据 shopify 的做法找到了解决方法。我没有重定向,而是发送下面的 html,该 html 重定向到带有 cookie 的所需页面

res.contentType("text/html").send(`<html>
        <head>
          <title></title>
          <script>
            (function(){window.location = "/"})()
          </script>
        </head>
        
        <body>
          <p>Logging in...</p>
        </body>
        
        </html>`);
于 2021-12-10T14:22:30.010 回答