我希望在我的登录表单中显示一条闪现消息,即当用户在表单中提供了错误的凭据时,但我不知道在哪里添加闪现,这让我有点困惑。请周围的人帮忙。
app.post('/login',passport.authenticate("local", {
successRedirect: "/",
failureRedirect: "/login"
}), function(req, res){
req.flash('error', err.message)
})
我仍然希望它显示来自表单的错误。我是新手 帮助
req.flash('error', err.message)
最佳答案
登录时需要在failureFlash:true中编码,设置为true
app.use(function(req,res,next){
res.locals.error = req.flash("error");
res.locals.success = req.flash("success")
next();
})
app.post("/dashlogin", passport.authenticate("local", {
successRedirect: "/dashboard",
failureRedirect: "/dashboard/login",
failureFlash: true,
}), function(req,res){
})
然后在页面中闪现给用户
<% if(error && error.length > 0) { %>
<div class="alert alert-danger" role="alert">
<div class="container">
<%= error %>
</div>
</div>
<% } %>
关于javascript - 如何在护照js中添加登录错误提示信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47615699/