0

So i am setting my flash messages inside my controller method like this:req.flash('info', 'flash is working') and then i console.log(req.flash()) in the controller to see if it works. Then in my app.js file i simply pass it on to a res.locals so that it is available to me in my templates but there i was receiving an empty object so i did console inside the middleware to assign res.locals and it was empty there as well. Why is this happening ?

app.use((req, res, next) => {
 res.locals.flashes = req.flash();
 res.locals.h = helpers;
 console.log(req.flash());
 next();
});

btw i know the first request is supposed to return empty flash object but the second one returns empty as well

Rhino
  • 55
  • 7

1 Answers1

0

Alright, i made a stupid mistake with the order of requiring the session module and because of that sessions were not working properly and i was getting an empty object in response as the flash messages were not really getting stored in the session. Fixing the order of modules fixed it for me.

Rhino
  • 55
  • 7