Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package com.firebase.ui.auth.ui.screens.phone

import android.content.Context
import android.util.Log
import androidx.activity.compose.BackHandler
import androidx.activity.compose.LocalActivity
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
Expand Down Expand Up @@ -340,6 +341,8 @@ fun PhoneAuthScreen(
}
)

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


if (content != null) {
content(state)
} else {
Expand Down Expand Up @@ -372,6 +375,7 @@ private fun DefaultPhoneAuthContent(
}

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

EnterVerificationCodeUI(
configuration = configuration,
isLoading = state.isLoading,
Expand Down
Loading