Skip to content

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

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

fix(auth): apply expiryMargin buffer to hasExpired check in setSession()#1331
grdsdev merged 2 commits intoguilherme/sdk-784-featauth-add-setsession-support-for-both-access_token-andfrom
copilot/sub-pr-1327

Conversation

Copy link
Copy Markdown

Copilot AI commented Mar 25, 2026

setSession() was checking token expiry with no buffer (exp <= now), while the rest of the codebase uses a 30-second pre-expiration margin via Constants.expiryMargin (as in Session.isExpired). This meant a nearly-expired token could be restored as a valid session, only to trigger an immediate refresh.

Change

  • hasExpired in setSession() now includes the same expiry margin, falling back to _callRefreshToken if the token expires within the margin:
// Before
final hasExpired = exp == null || exp <= timeNow;

// After
final hasExpired =
    exp == null || exp <= timeNow + Constants.expiryMargin.inSeconds;

🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

Copilot AI changed the title [WIP] [WIP] Address feedback on optional accessToken parameter in setSession() implementation fix(auth): apply expiryMargin buffer to hasExpired check in setSession() Mar 25, 2026
Copilot AI requested a review from grdsdev March 25, 2026 14:06
@github-actions github-actions bot added the auth This issue or pull request is related to authentication label Mar 25, 2026
@grdsdev grdsdev marked this pull request as ready for review March 25, 2026 14:40
@grdsdev grdsdev merged commit ee24630 into guilherme/sdk-784-featauth-add-setsession-support-for-both-access_token-and Mar 25, 2026
15 of 19 checks passed
@grdsdev grdsdev deleted the copilot/sub-pr-1327 branch March 25, 2026 14:48
grdsdev added a commit that referenced this pull request Mar 30, 2026
…n() (#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>
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