Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

req.flash() requires sessions

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

there is my configuration

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()
})

here I set flash message at controller action

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

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

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

req.flash() requires sessions

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

like image 487
Pavel Avatar asked Aug 23 '26 20:08

Pavel


1 Answers

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

like image 140
chris Avatar answered Aug 26 '26 12:08

chris



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!