0

Stack: Mongo/Redis, Express and Node

I have my sessions set as most other Stack Overflow posts point to. I am using Redis as my session store. This is my session setup:

app.use(session({
  resave: true,
  saveUninitialized: false,
  cookie: {
    maxAge: 60 * 1000 * 60 * 24 * 30 // 30 days
  },
  secret: config.sessionSecret,
  store: new RedisStore({
    url: config.redisDB,
    auto_reconnect: true
  })
}));

This comes before app.use(flash()); in my app.js file.

The only thing I can think of is I need sessions set up inside my routes file. But it seems wrong to set up sessions that many times. I do require my routes below where I setup sessions and flash.

Any idea what is going on here?

Error message:

req.flash() requires sessions

Stack trace points to line 55 of app.js which is res.locals.error = req.flash("error");

That comes before I call my routes but after I set my sessions. If I comment it out then it points to the route called. In this case the index route.

app.get('/', function(req, res) {
    res.render('index.ejs'); // load the index.ejs file
});

If I change the res.render out for res.send then it sends the message with no errors.

joshk132
  • 1,011
  • 12
  • 37

0 Answers0