簡體   English   中英

帶passport.js的動態failureRedirect

[英]Dynamic failureRedirect with passport.js

這是我的登錄功能atm:

app.post("/login", passport.authenticate("local", {
    failureRedirect: "/login?error=1"
}), function (req, res) {
    res.redirect(req.body.url || "/");
});

我需要將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 || "/");
});

它無法工作,因為req變量只在post的回調中出現...我該怎么辦?

您可以使用自定義回調來動態生成回調URL,因為req對象在其中可用。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM