fix(auth): fix "Already resumed" crash in phone auth SMS auto-verification - #2447
Conversation
19c6f52 to
655b983
Compare
|
/gemini review |
There was a problem hiding this comment.
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.
655b983 to
233082c
Compare
russellwheatley
left a comment
There was a problem hiding this comment.
Crash is gone, but first-callback-wins still drops auto-retrieval on the path this PR is fixing.
233082c to
8f0055f
Compare
dbaac07 to
f896825
Compare
cddff53 to
db6bec7
Compare
db6bec7 to
a9e5a01
Compare
Fixes #2446.
DefaultVerifieradapted Firebase'sOnVerificationStateChangedCallbacks— which can fire more than once for a single request — onto a single-shotsuspendCoroutine, resuming the same continuation fromonVerificationCompleted,onVerificationFailedandonCodeSent. On the SMS auto-retrieval path Firebase deliversonCodeSentand thenonVerificationCompleted, so the second resume threwIllegalStateException: Already resumedon the main thread inside Firebase's own dispatcher, where nothing in the library can catch it.Verifiernow returns aFlowbuilt withcallbackFlow, 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 reachesAuthState.SMSAutoVerifiedrather 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,PhoneAuthScreennow 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
PhoneAuthDefaultVerifierTestandPhoneAuthScreenVerificationLifecycleTest, 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-fix.mp4
after-final.mp4