I am trying to get persistent sessions working using RedisStore but whenever i close the browser the session is destroyed. I tried setting the maxAge and ttl but nothing makes the session survive a browser restart. What am i doing wrong?
The relevant parts of my code are:
var app = express();
var RedisStore = require('connect-redis')(express);
app.use(express.cookieParser('my secret key'));
  app.use(express.session({
  store: new RedisStore({
    host: 'localhost',
    port: 6379,
    ttl: (60000 * 24 * 30),
    cookie: { maxAge: (60000 * 24 * 30) }
  }),
  secret: 'my secret key'
}));
The cookie should belong in the object you pass to express.session, not in the object you pass to RedisStore.
Try the following:
app.use(express.session({
  store: new RedisStore({ host: 'localhost', port: 6379, ttl: (60000 * 24 * 30)}),
  cookie: { maxAge: (60000 * 24 * 30)},
  secret: 'my secret key'
}));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With