req.flash()需要会话 [英] req.flash() requires sessions

查看:121
本文介绍了req.flash()需要会话的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在查看Flash时遇到问题.我正在使用连接闪存.

I have a problem with flash at views. I am using connect-flash.

有我的配置

app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(express.cookieParser('secret'));
app.use(express.session());
app.use(passport.initialize());
app.use(passport.session());
app.use(flash());
app.use(function(req, res, next){
  res.locals.flash = req.flash
  next()
})

在这里,我在控制器动作时设置了Flash消息

here I set flash message at controller action

exports.new = function(req, res){
  req.flash('info', 'test')

  res.render("session/new", {
    title: 'Log In!'
  })
}

然后,当我尝试在视图中使用flash('info')时,出现此错误

and then, when I am trying to use flash('info') at view, I am getting this error

req.flash()需要会话

req.flash() requires sessions

我是nodejs的新手,如果这是一个愚蠢的问题,请原谅.

I am new to nodejs, so excuse me please if it's stupid question.

推荐答案

也许您是在将Flash数据传递到res.locals之前调用了req.session.destroy()吗?!

maybe you called req.session.destroy() before the flash-data is passed to res.locals?!

这篇关于req.flash()需要会话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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