首页 > 解决方案 > OpenID、Express、React - 通过身份验证将获得的令牌从后端发送到前端

问题描述

在身份验证用户被重定向到/auth/steam/authenticate存储在 url 中的数据后,这些数据正在使用函数 保存到JWT 令牌steam.authenticate,之后我试图用令牌将用户重定向到我的前端,但我不知道如何在我的前端处理该请求,因为我我没有从它发送请求。

目标:将用户令牌作为 cookie 保存在我的前端。

app.get("/auth/steam/authenticate", (req, res) => {
  try {
    steam.authenticate(req.url).then((user) => {
      const token = jwt.sign(user._json, process.env.JWT_TOKEN);
      return res.redirect("http://localhost:3000/"); //Frontend
    });

  } catch (error) {
    console.error(error);
  }
});

标签: node.jsreactjsexpressopenid

解决方案


推荐阅读