fix(auth): prevent signInWithRedirect hang after native sign-in sheet cancel (#14900) - #14901
Closed
soberm wants to merge 2 commits into
Closed
fix(auth): prevent signInWithRedirect hang after native sign-in sheet cancel (#14900)#14901soberm wants to merge 2 commits into
soberm wants to merge 2 commits into
Conversation
Cancelling a native sign-in sheet (e.g. Sign in with Apple on iOS Safari) left the inflightOAuth flag set, so every subsequent auth call hung forever awaiting an unsettleable promise. - TokenOrchestrator: bound the inflight wait with an internal 60s timeout that clears the persisted inflight flag and settles all waiters, so getTokens() proceeds as no-session instead of hanging. - cancelOAuthFlow: detect cancellation on visibilitychange/focus in addition to bfcache pageshow, guarded against OAuth response params, a grace period and the inflight flag; listeners are removed once the flow settles. fixes aws-amplify#14900
- capture a generation token when arming the inflight timeout and verify it before and after clearing, so a stale timer cannot wipe the inflight state of a newly started flow - add an explicit settled guard at the top of the timeout callback so the invariant does not rely solely on clearTimeout - cover both guards with unit tests
soberm
requested review from
a team,
avi-karthik,
pranavosu and
sarayev
as code owners
July 30, 2026 11:41
🦋 Changeset detectedLatest commit: 1ef88c1 The changes in this PR will be included in the next version bump. This PR includes changesets to release 3 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Contributor
Author
|
Evaluating if a new API or exposing an already existing function is a better option than timeouts or the safeguards. |
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.
Description of changes
Dismissing a native sign-in sheet (for example "Sign in with Apple" on iOS Safari) during
signInWithRedirect()leaves the persisted inflight OAuth flag set, because that dismissal is neither a navigation nor a bfcache restore and so the existing cancellation listener never fires. Every latergetTokens,fetchAuthSession, orgetCurrentUsercall then waits on a promise that never settles, and the app cannot authenticate again until site storage is cleared.This adds two internal safeguards: a bounded inflight wait in
TokenOrchestratorthat clears the stuck flag and lets token fetching report no session in progress, and broadened cancellation detection incancelOAuthFlowthat also reacts tofocusandvisibilitychange, guarded so a legitimate redirect is never interrupted.Issue #, if available
Fixes #14900
Description of how you validated changes
Unit tests were added for both layers, including the cases where cancellation must not be inferred, and the full auth package suite and build pass.
Checklist
yarn testpassesChecklist for repo maintainers
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.