Skip to content

docs: clarify setSession network behavior in doc comment#1332

Merged
grdsdev merged 2 commits into
guilherme/sdk-784-featauth-add-setsession-support-for-both-access_token-andfrom
copilot/sub-pr-1327-again
Mar 25, 2026
Merged

docs: clarify setSession network behavior in doc comment#1332
grdsdev merged 2 commits into
guilherme/sdk-784-featauth-add-setsession-support-for-both-access_token-andfrom
copilot/sub-pr-1327-again

Conversation

Copilot AI commented Mar 25, 2026

Copy link
Copy Markdown
Contributor

The setSession() doc comment incorrectly stated the session was restored "without a network round-trip" when a valid accessToken is provided — it still calls /user to populate the user object; only the /token refresh call is skipped.

Changes

  • gotrue_client.dart: Rewrote the setSession() doc comment to accurately state it skips the /token refresh round-trip but still issues a /user request to populate the session's user object.

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI changed the title [WIP] [WIP] Address feedback on accessToken parameter in setSession() implementation docs: clarify setSession network behavior in doc comment Mar 25, 2026
Copilot AI requested a review from grdsdev March 25, 2026 14:06
@grdsdev grdsdev marked this pull request as ready for review March 25, 2026 14:40
@grdsdev grdsdev merged commit 8946afa into guilherme/sdk-784-featauth-add-setsession-support-for-both-access_token-and Mar 25, 2026
@grdsdev grdsdev deleted the copilot/sub-pr-1327-again branch March 25, 2026 14:40
grdsdev added a commit that referenced this pull request Mar 30, 2026
* Initial plan

* docs: clarify setSession skips /token refresh but still calls /user

Co-authored-by: grdsdev <5923044+grdsdev@users.noreply.github.com>
Agent-Logs-Url: https://github.com/supabase/supabase-flutter/sessions/db643f38-73ec-4b87-92e3-9d995d319a73

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: grdsdev <5923044+grdsdev@users.noreply.github.com>
grdsdev added a commit that referenced this pull request Apr 1, 2026
* feat(auth): add optional accessToken parameter to setSession()

Mirrors the JS SDK behaviour: when both tokens are supplied and the
access token has not yet expired, the session is restored directly
(via a getUser() call) without an extra /token refresh round-trip.
If the access token is expired or omitted the existing _callRefreshToken
path is preserved unchanged.

- Valid, non-expired accessToken: calls getUser(accessToken), builds
  Session locally, fires AuthChangeEvent.signedIn.
- Expired accessToken: falls back to _callRefreshToken(refreshToken).
- Malformed accessToken: throws AuthInvalidJwtException.
- Empty accessToken: throws AuthSessionMissingException.

Linear: SDK-784

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* docs: clarify setSession network behavior in doc comment (#1332)

* Initial plan

* docs: clarify setSession skips /token refresh but still calls /user

Co-authored-by: grdsdev <5923044+grdsdev@users.noreply.github.com>
Agent-Logs-Url: https://github.com/supabase/supabase-flutter/sessions/db643f38-73ec-4b87-92e3-9d995d319a73

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: grdsdev <5923044+grdsdev@users.noreply.github.com>

* fix(auth): apply expiryMargin buffer to hasExpired check in setSession() (#1331)

* Initial plan

* fix(auth): apply expiryMargin buffer to hasExpired check in setSession()

Co-authored-by: grdsdev <5923044+grdsdev@users.noreply.github.com>
Agent-Logs-Url: https://github.com/supabase/supabase-flutter/sessions/80e8e775-47d3-4e08-aa75-07f715c27411

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: grdsdev <5923044+grdsdev@users.noreply.github.com>

* fix(gotrue): address setSession review feedback

- Use exp - iat for expiresIn (full token lifetime, not remaining seconds)
- Deduplicate concurrent fast-path calls via _refreshTokenCompleter
- Use idiomatic throwsA in error-throwing tests

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* test(gotrue): add edge case tests for setSession fast path

- New set_session_test.dart with 10 mock-based tests covering:
  - Validation order (empty RT checked before AT)
  - Expiry margin boundary (exp within 30 s treated as expired)
  - JWT without exp claim falls back to refresh
  - expiresIn = exp - iat when both claims present
  - expiresIn = null when iat absent
  - expiresAt matches JWT exp
  - Preserved access/refresh token values
  - Fast path fires signedIn, fallback fires tokenRefreshed
  - Concurrent calls deduplicated to one /user request
  - signedIn fires exactly once under concurrent load
- Fix remaining try/catch in client_test.dart to use throwsA

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* test(gotrue): fix expiresIn tests by using raw base64url JWT crafting

dart_jsonwebtoken auto-injects an iat claim when signing, which broke:
- 'expiresIn equals exp minus iat' (iat value was overridden)
- 'expiresIn is null when iat absent' (iat was auto-added)

Replace dart_jsonwebtoken usage with _makeRawJwt(), which base64url-encodes
the payload map directly (no auto-claims, no signature verification needed).
Also removes the dart_jsonwebtoken import from the test file.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* simplify setSession

* remove concurrent tests

* docs: simplify doc string

---------

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants