简体   繁体   中英

Dynamic failureRedirect with passport.js

This is my login function 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:

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?

您可以使用自定义回调来动态生成回调URL,因为req对象在其中可用。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM