Dynamic failureRedirect with passport.js

社会主义新天地 提交于 2019-12-14 01:06:08

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!