Skip to content

fix(auth): fix "Already resumed" crash in phone auth SMS auto-verification - #2447

Merged
russellwheatley merged 1 commit into
version-10.0.0-beta04from
fix/phone-auth-already-resumed
Aug 18, 2026
Merged

fix(auth): fix "Already resumed" crash in phone auth SMS auto-verification#2447
russellwheatley merged 1 commit into
version-10.0.0-beta04from
fix/phone-auth-already-resumed

Conversation

@demolaf

@demolaf demolaf commented Aug 13, 2026

Copy link
Copy Markdown
Member

Fixes #2446.

DefaultVerifier adapted Firebase's OnVerificationStateChangedCallbacks — which can fire more than once for a single request — onto a single-shot suspendCoroutine, resuming the same continuation from onVerificationCompleted, onVerificationFailed and onCodeSent. On the SMS auto-retrieval path Firebase delivers onCodeSent and then onVerificationCompleted, so the second resume threw IllegalStateException: Already resumed on the main thread inside Firebase's own dispatcher, where nothing in the library can catch it.

Verifier now returns a Flow built with callbackFlow, so several callbacks are simply several emissions and there is no continuation left to double-resume. A credential auto-retrieved after the code was sent now reaches AuthState.SMSAutoVerified rather than being discarded, so the user is no longer asked to type a code Firebase has already verified.

Because the collection stays open for the verification window instead of returning at onCodeSent, PhoneAuthScreen now cancels superseded attempts on send, resend, change-number and success, and skips auto sign-in while a manually submitted code is still signing in. Cancellation is not reported to the host as an error.

Added PhoneAuthDefaultVerifierTest and PhoneAuthScreenVerificationLifecycleTest, covering every callback ordering, the auto-retrieval timeout terminal, and the screen's cancellation and guard lifecycle — the multi-callback cases fail against the old code.

Preview

  • Before
before-fix.mp4
  • After
after-final.mp4

@demolaf
demolaf changed the base branch from master to version-10.0.0-beta04 August 13, 2026 14:29
gemini-code-assist[bot]

This comment was marked as off-topic.

@demolaf
demolaf force-pushed the fix/phone-auth-already-resumed branch 2 times, most recently from 19c6f52 to 655b983 Compare August 14, 2026 12:52
@demolaf

demolaf commented Aug 14, 2026

Copy link
Copy Markdown
Member Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request improves phone number verification by handling coroutine cancellation and multiple callbacks more robustly. It transitions from suspendCoroutine to suspendCancellableCoroutine and introduces an AtomicBoolean to prevent multiple callbacks from resuming the continuation. Additionally, user-initiated cancellation now clears the pending loading state and propagates the CancellationException directly rather than emitting an error state. Comprehensive unit tests have been added to cover these scenarios. The review feedback suggests registering an invokeOnCancellation listener to mark the operation as resolved upon cancellation, which prevents late-arriving callbacks from attempting to resume the cancelled continuation.

@demolaf
demolaf marked this pull request as ready for review August 14, 2026 13:48
@demolaf
demolaf force-pushed the fix/phone-auth-already-resumed branch from 655b983 to 233082c Compare August 14, 2026 14:03

@russellwheatley russellwheatley left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Crash is gone, but first-callback-wins still drops auto-retrieval on the path this PR is fixing.

Comment thread auth/src/main/java/com/firebase/ui/auth/FirebaseAuthUI.kt Outdated
@demolaf
demolaf force-pushed the fix/phone-auth-already-resumed branch from 233082c to 8f0055f Compare August 18, 2026 01:55
@demolaf
demolaf force-pushed the version-10.0.0-beta04 branch from dbaac07 to f896825 Compare August 18, 2026 09:55
@demolaf
demolaf force-pushed the fix/phone-auth-already-resumed branch 2 times, most recently from cddff53 to db6bec7 Compare August 18, 2026 11:27
@demolaf
demolaf force-pushed the fix/phone-auth-already-resumed branch from db6bec7 to a9e5a01 Compare August 18, 2026 12:53

@russellwheatley russellwheatley left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@russellwheatley
russellwheatley merged commit 637e13a into version-10.0.0-beta04 Aug 18, 2026
9 checks passed
@russellwheatley
russellwheatley deleted the fix/phone-auth-already-resumed branch August 18, 2026 13:54
@github-project-automation github-project-automation Bot moved this from Backlog to Done in studio-2394994192-60a69 Aug 18, 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.

Phone Auth crashes with "Already resumed" in DefaultVerifier.onVerificationCompleted

2 participants