Skip to content

docs(gotrue): clarify Session.expiresAt is in seconds#1447

Merged
spydon merged 1 commit into
mainfrom
fix/session-expires-at-doc-clarification
Jun 22, 2026
Merged

docs(gotrue): clarify Session.expiresAt is in seconds#1447
spydon merged 1 commit into
mainfrom
fix/session-expires-at-doc-clarification

Conversation

@spydon

@spydon spydon commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

Description

Clarifies the doc comment for Session.expiresAt to state that the value is a Unix timestamp in seconds, and shows the correct conversion to DateTime.

Context

While investigating #1202 ("Session expiresAt always corrupted after hot restart"), I verified the reported symptom is not a library bug:

  • Session.expiresAt is derived from the access token's JWT exp claim (unix seconds), not from the persisted expires_at JSON value. Session.fromJson doesn't even read expires_at, so persistence/deserialization cannot corrupt it.
  • Every internal consumer (isExpired, the auto-refresh tick, supabase_client.dart) correctly multiplies by 1000.
  • The reporter's logged 1970-... date decodes to a millisecond value that is exactly a valid 2026 seconds timestamp, i.e. their own code passed expires_at (seconds) into DateTime.fromMillisecondsSinceEpoch without * 1000.

The real underlying problem is an ergonomics footgun: the previous doc comment didn't state the unit. This PR fixes that.

No behavior change; existing session_test.dart tests pass.

Refs #1202

The expires_at value is a Unix timestamp in seconds, consistent with
supabase-js. Without the unit stated, consumers reach for
DateTime.fromMillisecondsSinceEpoch without multiplying by 1000, which
yields a 1970 date and makes the session always read as expired.

Refs #1202
@spydon spydon requested a review from a team as a code owner June 22, 2026 09:52
@github-actions github-actions Bot added the auth This issue or pull request is related to authentication label Jun 22, 2026
Comment thread packages/gotrue/lib/src/types/session.dart
@spydon spydon merged commit 9dffae1 into main Jun 22, 2026
27 of 28 checks passed
@spydon spydon deleted the fix/session-expires-at-doc-clarification branch June 22, 2026 10:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

auth This issue or pull request is related to authentication

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants