问题
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?
回答1:
You can use Custom Callbacks to dynamically generate callbacks urls, as the req object is available inside them.
来源:https://stackoverflow.com/questions/25808827/dynamic-failureredirect-with-passport-js