Passport.authenticate 似乎在剥离部分 header

Passport.authenticate seems to be stripping partials header

我正在尝试使用 NodeJS、Express 和 Mongoose 构建身份验证部分。

我使用 passport,passport-local 和 passport-local-mongoose。

最初,我认为它可能与 express-session 有关,所以我尝试用 cookie-session 替换那个,但没有骰子。

对新注册的用户进行身份验证并将其重定向到仪表板后,仪表板无法正确呈现。似乎 header 我的一部分不包括在内。未应用样式,包含在页脚中的脚本在第 1 行生成错误 -> $ 未定义。

我已将 app.js 文件配置为:

app.use(passport.initialize());
app.use(passport.session());

我的用户模式中有这个:

userSchema.plugin(passportLocalMongoose, {
usernameField : "email"
});

我把它放在我的用户路由中: (它也曾经在 app.js 文件中,但结果相同)

passport.use(User.createStrategy());
passport.serializeUser(User.serializeUser());
passport.deserializeUser(User.deserializeUser());


.
.
} else {
passport.authenticate("local")(req, res, function() {
                res.redirect(req.user.email)
            })
.
.

如果我在没有对用户进行身份验证的情况下执行 res.redirect(req.user.email) 页面会按应有的方式呈现,所以这告诉我可能是 passport.authenticate() 导致了它.

如有任何建议,我们将不胜感激。让我知道是否需要包含更多内容,但我尽量减少内容,因为有很多内容与此问题无关。

终于找到导致此行为的原因。我已将 req.user 设置为 res.locals.currentUser 并在 body 的 header 部分中使用了它。不知道为什么这现在不起作用,因为我以前让它工作过......也许它与 EJS 有关,但无论哪种方式,在剥离一些不必要的部分后它现在再次工作。