Skip to content

fix(auth): handle system back press in phone auth flow#2418

Closed
just1and0 wants to merge 2 commits into
masterfrom
fix/2058-phone-auth-back-press
Closed

fix(auth): handle system back press in phone auth flow#2418
just1and0 wants to merge 2 commits into
masterfrom
fix/2058-phone-auth-back-press

Conversation

@just1and0

Copy link
Copy Markdown
Contributor

Summary

  • Adds BackHandler to PhoneAuthScreen so the system back button is handled consistently for both default and custom phone content
  • The base handler delegates to onCancel(), which navigates to the method picker or prevents premature activity finish in phone-only flows
  • The default UI adds a step-specific override on the verification code screen: system back returns to phone number entry instead of cancelling
  • Custom phoneContent slots inherit the base behavior and can override with their own BackHandler

Fixes #2058

Test plan

  • Launch phone auth as the only provider — verify system back does not finish the activity
  • Launch phone auth with multiple providers — verify system back returns to method picker
  • On verification code screen — verify system back returns to phone number entry
  • With custom phoneContent slot — verify consumer BackHandler overrides the default

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.

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

Copy link
Copy Markdown

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 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() }

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

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).

Suggested change
BackHandler { onCancel() }
BackHandler(enabled = !isLoading) { onCancel() }

}

PhoneAuthStep.EnterVerificationCode -> {
BackHandler { state.onChangeNumberClick() }

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

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.

Suggested change
BackHandler { state.onChangeNumberClick() }
BackHandler(enabled = !state.isLoading) { state.onChangeNumberClick() }

@just1and0

Copy link
Copy Markdown
Contributor Author

Closing — no user interest on the original issue (no thumbs up), and confirmed by team that this isn't worth pursuing.

@just1and0 just1and0 closed this Jul 23, 2026
@github-project-automation github-project-automation Bot moved this from Backlog to Done in studio-2394994192-60a69 Jul 23, 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.

Disable back press in Firebase Auth Phone

1 participant