When setting my flash messages inside the controller method like this:
req.flash('info', 'flash is working')
, I then use console.log(req.flash())
in the controller to verify if it works. However, upon passing it on to res.locals in my app.js file for availability in templates, I noticed that I was receiving an empty object. This led me to console log inside the middleware where I was assigning res.locals and found it empty there as well. What could be causing this issue?
app.use((req, res, next) => {
res.locals.flashes = req.flash();
res.locals.h = helpers;
console.log(req.flash());
next();
});
By the way, I understand that the first request is supposed to return an empty flash object, but the second one returns empty as well.