node.js - 使用 Node.js Passport 进行动态重定向
问题描述
我还没有找到这个话题的最新答案;我希望我没有被卡住,因为我不理解旧的......
如果用户之前访问过给定页面,我想在登录后将用户重定向到不同的页面。
If thisVariable is true,
Log the user in,
And redirect to /page1/thisVariable
Else,
Log the user in
And redirect to /page2.
使用 passeport,这是我原来的基本登录路线:
app.post('/login', passport.authenticate("local", {
successRedirect : '/',
failureRedirect : '/login',
failureFlash: "Please double check your credentials ❌"
}), (req, res)=>{
req.flash("success", "You're logged in ✅");
}
);
我最好的尝试调整它是这段代码,它不起作用:
app.post('/login', (req, res)=>{
console.log("VARIABLE=> ", req.body.variable) //(My variable does show up here)
if(req.body.variable){
passport.authenticate("local", {
successRedirect : '/page1/'+req.body.variable,
failureRedirect : '/login',
failureFlash: "Please double check your credentials ❌"
})
req.flash("success", "You're logged in ✅");
} else {
passport.authenticate("local", {
successRedirect : '/',
failureRedirect : '/login',
failureFlash: "Please double check your credentials ❌"
})
req.flash("success", "You're logged in ✅");
}
});
该代码不会引发任何错误,请求仍处于待处理状态。
有什么办法可以把它改正吗?非常感谢 !
解决方案
推荐阅读
- firebase - 在 Flutter 中捕获云 Firestore 文档快照错误
- ssl - GKE - 使用 Google 托管证书 (mcrt) 进行 SSL 连接到可扩展服务代理 (ESP)
- php - oath2 访问令牌 API 响应“expires_on”日期无效
- angular - 使用模板驱动验证未定义角度变量错误
- spring - 使用 SpringFox 的 Swagger 中未列出 OAuth2 授权端点
- python - 如何在 Kivy 中填充小部件?
- python - CS50 金融的符号无效,即使我使用了正确的符号
- c# - 当您将 lambda 函数作为参数传递给任务时,它是在任务线程还是调用者线程上运行?
- python - 如何去掉方括号
- reactjs - ag-grid-react reactjs中的行点击事件的名称是什么?