fix(auth): handle system back press in phone auth flow#2418
Conversation
Fixes #2058 by adding BackHandler to the default phone auth UI so the system back button behaves consistently with the UI back arrow. On the phone number entry screen, back navigates to the method picker (or does nothing when phone is the only provider). On the verification code screen, back returns to the phone number entry step. Users with custom phoneContent slots can add their own BackHandler for full control.
Fixes #2058 by adding BackHandler to PhoneAuthScreen so the system back button is handled consistently for both default and custom phone content. The base handler delegates to onCancel (navigating to the method picker or preventing premature activity finish in phone-only flows). The default UI adds a step-specific override on the verification code screen to return to phone number entry. Custom phoneContent slots inherit the base behavior and can override with their own BackHandler.
There was a problem hiding this comment.
Code Review
This pull request integrates BackHandler into the PhoneAuthScreen to manage back navigation during the phone authentication flow. The review feedback recommends disabling back navigation while authentication or verification requests are in progress to prevent race conditions and ensure state consistency.
| } | ||
| ) | ||
|
|
||
| BackHandler { onCancel() } |
There was a problem hiding this comment.
To prevent race conditions or inconsistent states, the back button should be disabled while an authentication operation is in progress (isLoading is true). If the user is allowed to navigate back or cancel while a network request is active, the background task might still succeed or fail later, leading to unexpected state transitions (e.g., suddenly logging in the user or showing an error dialog after they have already navigated away).
| BackHandler { onCancel() } | |
| BackHandler(enabled = !isLoading) { onCancel() } |
| } | ||
|
|
||
| PhoneAuthStep.EnterVerificationCode -> { | ||
| BackHandler { state.onChangeNumberClick() } |
There was a problem hiding this comment.
Similarly, the back handler on the verification code screen should be disabled while a verification request is in progress (state.isLoading is true). This prevents the user from returning to the phone number entry screen while the code is actively being verified, which could otherwise lead to a race condition if the verification completes successfully in the background.
| BackHandler { state.onChangeNumberClick() } | |
| BackHandler(enabled = !state.isLoading) { state.onChangeNumberClick() } |
|
Closing — no user interest on the original issue (no thumbs up), and confirmed by team that this isn't worth pursuing. |
Summary
BackHandlertoPhoneAuthScreenso the system back button is handled consistently for both default and custom phone contentonCancel(), which navigates to the method picker or prevents premature activity finish in phone-only flowsphoneContentslots inherit the base behavior and can override with their ownBackHandlerFixes #2058
Test plan
phoneContentslot — verify consumerBackHandleroverrides the default