我是 React 和 Node 的新手。我有两个文件夹:
- 客户端,托管在 3000 上
- 服务器,3001 上的 express
注册对我来说工作正常,但在身份验证后 successRedirect:
到 http://localhost:3001/login
如何将其重定向到客户端 http://localhost:3000/login
passport.authenticate('local-signup',{
successRedirect:'/login',
failureRedirect: '/register',
failureFlash : true
})(req, res);
最佳答案
您可以将完全限定的 url
传递给重定向,如 Express Api Documentation 中所述。
实现此目的的方法之一是在 response
属性上使用 redirect
设置回调函数(您可以相应地修改它):
app.get("/auth/google/callback"",
passport.authenticate("local-signup"),
(req , res) => {
res.redirect("/login");
});
关于node.js - 将 Express 重定向到 React 页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49360059/