After upgrading to Express 3 I went through the "joys" of implementing connect-flash and have it working.
I implement like this:
var flash = require('connect-flash');
app.use(flash());
app.use( function (req, res, next) {
res.locals.everyauth.user = req.user;
res.locals.user = req.user;
res.locals.flash = req.flash();
next();
});
I display the flash alerts in my jade layout template (used by all pages, and have a similar line for flash.info, flash.warning, etc) like this:
- if ('undefined' !== typeof flash.error && flash.error.length)
- each msg in flash.error
div.error= msg
All is well EXCEPT when I render my /login and /register pages via express, when I get a "flash is not defined" error. Any ideas?