Passport.js session expiration timezone conversion limits
0 reputation · 28 May 2023, 12:37 UTC
0 reputation · 28 May 2023, 12:37 UTC
Passport.js delegates session management to express-session, where the expires option is interpreted as a UTC timestamp without timezone metadata. The goal is to present session expiration times to users in their local time zone, or at least expose timezone-aware session metadata, without breaking server-side validation.
The uncertainty is whether Passport.js or express-session provides any documented mechanism for converting UTC session timestamps to a user's local time zone, or if daylight saving time transitions are accounted for during session validity calculations. Existing documentation indicates that session validation occurs strictly in UTC, but it is unclear whether the middleware exposes any hooks for timezone-aware display or whether this responsibility is entirely delegated to the application layer.
Should Passport.js expose timezone-aware session metadata for client-side rendering, is there a documented pattern for converting express-session expires values to local time within the middleware, and how are daylight saving time transitions handled when calculating remaining session validity across different user regions?
34775 reputation · 28 May 2023, 16:01 UTC
No. Passport.js does not expose timezone-aware session metadata and does not convert session expiration times. Session validity is handled entirely by express-session, which validates in UTC. There is no documented middleware hook in Passport.js or express-session for automatic timezone-aware display. Daylight saving time transitions do not affect server-side validity calculations.
expires as a UTC timestamp without timezone metadata. Validation compares the current UTC clock to that fixed moment.Confirmed: No API in Passport.js or express-session converts the UTC expiration to a user’s local time zone. Responsible for display is the application layer.
Likely: Any timezone-aware rendering must be implemented by you. The middleware intentionally stays timezone-agnostic to avoid coupling server validation to client locale.
req.session.cookie.expires or the store’s expires field.new Date(utcString).toLocaleString() or a library like luxon/date-fns-tz using the browser’s timezone.maxAge and store expiration.Assumption: express-session is used with its default cookie handling and a store that preserves the UTC timestamp. If a custom session store transforms the timestamp, the raw UTC value may not be directly accessible.
One missing diagnostic detail that changes the recommendation: which session store you use and whether you need server-side rendered expiration text. Store-specific serialization and whether the client timezone is known ahead of rendering affect whether conversion should happen server-side or client-side.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.