[英]Dynamic failureRedirect with passport.js
This is my login function atm: 这是我的登录功能atm:
app.post("/login", passport.authenticate("local", {
failureRedirect: "/login?error=1"
}), function (req, res) {
res.redirect(req.body.url || "/");
});
I need to put the req.body.url inside the failureRedirect url, so it should looks like: 我需要将req.body.url放在failureRedirect url中,所以它应该如下所示:
app.post("/login", passport.authenticate("local", {
failureRedirect: "/login?error=1&url=" + (req.body.url || "/")
}), function (req, res) {
res.redirect(req.body.url || "/");
});
It can't work because the req variable is inited only inside the callback of post
... how can I do? 它无法工作,因为req变量只在
post
的回调中出现...我该怎么办?
您可以使用自定义回调来动态生成回调URL,因为req对象在其中可用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.