Skip to content

fix(auth): prevent signInWithRedirect hang after native sign-in sheet cancel (#14900) - #14901

Closed
soberm wants to merge 2 commits into
aws-amplify:mainfrom
soberm:fix/14900-oauth-inflight-timeout
Closed

fix(auth): prevent signInWithRedirect hang after native sign-in sheet cancel (#14900)#14901
soberm wants to merge 2 commits into
aws-amplify:mainfrom
soberm:fix/14900-oauth-inflight-timeout

Conversation

@soberm

@soberm soberm commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

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 later getTokens, fetchAuthSession, or getCurrentUser call 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 TokenOrchestrator that clears the stuck flag and lets token fetching report no session in progress, and broadened cancellation detection in cancelOAuthFlow that also reacts to focus and visibilitychange, 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

Checklist for repo maintainers

  • Verify E2E tests for existing workflows are working as expected or add E2E tests for newly added workflows
  • New source file paths included in this PR have been added to CODEOWNERS, if appropriate

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

soberm added 2 commits July 30, 2026 11:40
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
soberm requested review from a team, avi-karthik, pranavosu and sarayev as code owners July 30, 2026 11:41
@changeset-bot

changeset-bot Bot commented Jul 30, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 1ef88c1

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
@aws-amplify/auth Patch
@aws-amplify/pubsub Patch
aws-amplify Patch

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

@soberm

soberm commented Jul 30, 2026

Copy link
Copy Markdown
Contributor Author

Evaluating if a new API or exposing an already existing function is a better option than timeouts or the safeguards.

@soberm soberm closed this Jul 30, 2026
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.

signInWithRedirect cancelled on iOS Safari leaves inflightOAuth set — then signIn() hangs forever

1 participant