7

How can I make the connect.sid cookie itself only a session cookie instead of a persistent one?

I unsuccessfully tried

app.use(express.session({cookie: { path: '/', httpOnly: true}, secret:'eeuqram'}));

But the cookie still had the expiration timestamp.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Ustaman Sangat
  • 1,505
  • 1
  • 14
  • 26
  • Did you try this? http://stackoverflow.com/questions/4371178/session-only-cookie-for-express-js – glortho Jan 12 '12 at 21:17
  • Actually, that is where I had commented first. I know how to create a session only cookie but I wanted the default cookies created when I am using the session (the default name for that cookie is connect.sid) to be a non-persistent cookie. – Ustaman Sangat Jan 12 '12 at 22:37
  • I think you forgot the most important part => expires: new Date() - 1? – Alfred Jan 13 '12 at 03:13
  • 2
    "new Date() - 1" wouldn't it be evaluated at nodejs server? If so how'd that relate to what the browser's timezone is? I tried with chrome and it makes the cookie and thus the session expire - and I am left with too many redirects (I am using a SSO solution). – Ustaman Sangat Jan 13 '12 at 16:59

1 Answers1

18
 app.use(express.session({cookie: { path: '/', httpOnly: true, maxAge: null}, secret:'eeuqram'}));

The above worked. So by setting maxAge to be null, I did manage expressjs to use session cookies. Phew.

Ustaman Sangat
  • 1,505
  • 1
  • 14
  • 26