Search code examples
node.jssessioncookiesnode.js-connect

nodejs connect session cookie not setting on some machines


I have a minimal connect session setup on my nodejs app:

connect.cookieParser(),
connect.session({ secret: 'asdfg', cookie: { maxAge: 60 * 60 * 1000 }}),

But when testing my site on other machines the session cookie does not get set at all. On my Mac the session cookie is set like normal in both Chrome and Firefox. On my virtual Windows the session cookie does not get set on either Chrome or Firefox. On one friend's Windows the sessions are apparently not getting set either, but on another friend's Windows the sessions seem to be working. I've checked cookie setting and headers on my virtual Windows Chrome, but nothing seems to be different, it's just refusing to create a cookie...

Any ideas why session cookies would apparently be getting set on some machines and not others?


Solution

  • The answer finally dawned on me shortly after posting...

    Always check your system timezone or your sessions could be expiring instantly. Even if the time is right, the timezone will offset that time from UTC which is what sessions use. It will affect the expiration time of any session, but sessions that are set to expire in only an hour or two may not get set at all.