Skip to content

fix(supabase_flutter): clear auth params from web URL after exchange#1456

Merged
spydon merged 2 commits into
mainfrom
fix/web-oauth-code-cleanup
Jun 22, 2026
Merged

fix(supabase_flutter): clear auth params from web URL after exchange#1456
spydon merged 2 commits into
mainfrom
fix/web-oauth-code-cleanup

Conversation

@spydon

@spydon spydon commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

What

On Flutter web, after a successful OAuth/PKCE sign-in the auth code (or implicit-flow tokens) stays in the browser URL. On the next page refresh, supabase_flutter reads that URL again, sees the stale code, and tries to exchange it a second time. The code verifier was already consumed and removed during the first exchange, so the second attempt throws:

AuthException(message: Code verifier could not be found in local storage.)

This logs the user out on every refresh while the code is still in the URL.

Fix

After a successful getSessionFromUrl on web, strip the auth parameters from the browser URL using history.replaceState, mirroring what supabase-js does. Unrelated query and fragment parameters are preserved.

  • clear_auth_url_parameters.dart holds the pure, testable URL-stripping logic.
  • clear_auth_url_parameters_web.dart / _stub.dart follow the existing conditional-import pattern (if (dart.library.js_interop)) so non-web platforms get a no-op.
  • The cleanup is invoked from _handleDeeplink only on web after the exchange succeeds.

Test

Added clear_auth_url_parameters_test.dart covering PKCE code, implicit fragment tokens, error params, and preservation of unrelated params.

Closes #836

On web the OAuth/PKCE auth code stays in the browser URL after a
successful exchange. Refreshing the page re-reads the spent code and
fails with "Code verifier could not be found in local storage." because
the verifier was already consumed.

Strip the auth parameters from the browser URL via history.replaceState
after a successful getSessionFromUrl on web.

Closes #836
@spydon spydon requested a review from a team as a code owner June 22, 2026 16:07
…om API scan

Use Map.of instead of Map.from for prefer-iterable-of, and add a
.sdk-parse-ignore so the capability-matrix scan does not treat the
internal lib/src URL-cleanup helpers as new public API.
@spydon spydon merged commit 8b1e1b2 into main Jun 22, 2026
22 checks passed
@spydon spydon deleted the fix/web-oauth-code-cleanup branch June 22, 2026 17:06
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.

Flutter Web - Code verifier could not be found in local storage

2 participants