fix(supabase_flutter): clear auth params from web URL after exchange#1456
Merged
Conversation
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
grdsdev
approved these changes
Jun 22, 2026
…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.
grdsdev
approved these changes
Jun 22, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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_flutterreads that URL again, sees the stalecode, 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:This logs the user out on every refresh while the
codeis still in the URL.Fix
After a successful
getSessionFromUrlon web, strip the auth parameters from the browser URL usinghistory.replaceState, mirroring whatsupabase-jsdoes. Unrelated query and fragment parameters are preserved.clear_auth_url_parameters.dartholds the pure, testable URL-stripping logic.clear_auth_url_parameters_web.dart/_stub.dartfollow the existing conditional-import pattern (if (dart.library.js_interop)) so non-web platforms get a no-op._handleDeeplinkonly on web after the exchange succeeds.Test
Added
clear_auth_url_parameters_test.dartcovering PKCE code, implicit fragment tokens, error params, and preservation of unrelated params.Closes #836