My flash messages seem to require an additional manual reload of the page for them to appear.
Here’s an example of how I’m using it:
if (password.length < 12) {
req.flash('error', 'Password must be at least 12 characters long.');
return res.redirect('/signup');
}
It then redirects to /signup which displays this pug view:
extends auth
block content
h4.card-title Sign Up
// Debug output for flash messages
pre= JSON.stringify(flashMessages)
if flashMessages.error
.alert.alert-danger
each msg in flashMessages.error
div= msg
Upon redirect, no errors are displayed but if I refresh the page, the errors then appear.
Here’s where I configure it:
// Initialize Session Store
const SequelizeStore = require('connect-session-sequelize')(session.Store);
// Initialize Express Web App
const app = express();
// add various locals
app.locals.config = config;
app.locals.moment = moment;
// Initialize HTTP Server
const server = http.createServer(app);
//app.use(cookieParser(process.env.APP_KEY)); apparently don't need this with express-session 1.15 and later (we have 1.18)
// setup morgan to log HTTP requests to winston
app.use(morgan('tiny', { stream: { write: message => logger.debug(message.trim()) } }));
// Initialize Session
const sessionStore = new SequelizeStore({ db: sequelize });
app.use(session({
secret: process.env.APP_KEY,
store: sessionStore, // Use SequelizeStore as the session store
resave: false, // 'resave' and 'saveUninitialized' set as per express-session recommendations
saveUninitialized: false,
cookie: { secure: process.env.NODE_ENV === 'production' }
}));
// Sync the session store table
sessionStore.sync();
I tried searching for a solution but couldn’t find one.
Thanks in advance