我在 mongoose 函数中调用 req.flash 时遇到问题。我试过点燃一切。在我的代码的一部分中它可以工作,但在其他部分中却没有。
我的代码:
router.post('/chngpwd', function(req, res, next) {
var {currentpassword, newpassword, confirmnewpassword} = req.body;
var uid = req.session.passport.user;
if (newpassword == confirmnewpassword) {
User.findById(uid).then(dbres => {
req.flash('error_msg',"THIS MESSAGE DON'T WORK"); //DONT WORK
});
}else {
req.flash('error_msg',"New passwords don't match"); //WORKS
}
res.redirect('/adminpanel/1');
});