动态失败使用passport.js重定向 [英] Dynamic failureRedirect with passport.js

查看:74
本文介绍了动态失败使用passport.js重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的登录功能atm:

This is my login function atm:

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

我需要将req.body.url放在failureRedirect网址中,所以它应该像这样:

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 || "/");
});

它不起作用,因为req变量仅在post的回调内部初始化...我该怎么办?

It can't work because the req variable is inited only inside the callback of post... how can I do?

推荐答案

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

You can use Custom Callbacks to dynamically generate callbacks urls, as the req object is available inside them.

这篇关于动态失败使用passport.js重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆