【问题标题】:Redirecting with user data使用用户数据重定向
【发布时间】:2022-12-17 06:15:51
【问题描述】:

我想弄清楚如何在身份验证后发回用户数据。通常,当您想要返回信息时,您只需在前端进行 api 调用并将其发回,但是为了进行身份验证,我使用的是 oath,而不是 api 调用它的链接。

前端

function App() {
  return (
    <>
      <div className="App">welcome to paragon over prime builds.</div>
      <br></br>
      <a href="http://localhost:3001/auth/google">Sign in</a>
    </>
  );
}

后端

app.get(
  "/auth/google",
  passport.authenticate("google", { scope: ["email", "profile"] })
);

app.get(
  "/auth/google/oauth2callback",
  passport.authenticate("google", {
    successRedirect: "/auth/google/success",
    failureRedirect: "/auth/google/failure",
    failureMessage: true,
  })
);

// respond here
// redirect???
app.get("/auth/google/failure", (req, res) => {
  // res.status(400).send({ error: "something went wrong" });
});

// respond here
// redirect???
app.get("/auth/google/success", isLoggedIn, (req, res) => {
  // res.status(200).send(req.user.username);
});

我应该为重定向做什么? 像使用 res.redirect("front end url").send(req,user) 这样的东西???

【问题讨论】:

    标签: reactjs express passport.js


    【解决方案1】:

    【讨论】:

      猜你喜欢
      • 2020-01-31
      • 1970-01-01
      • 2011-04-10
      • 1970-01-01
      • 2011-09-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多