Skip to content

Commit 98d196c

Browse files
committed
fix(auth): read auth state per authUI instance when clearing loading on dispose
1 parent 577d717 commit 98d196c

1 file changed

Lines changed: 5 additions & 6 deletions

File tree

auth/src/main/java/com/firebase/ui/auth/ui/screens/phone/PhoneAuthScreen.kt

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import androidx.compose.runtime.mutableIntStateOf
2626
import androidx.compose.runtime.mutableStateOf
2727
import androidx.compose.runtime.remember
2828
import androidx.compose.runtime.rememberCoroutineScope
29-
import androidx.compose.runtime.rememberUpdatedState
3029
import androidx.compose.runtime.saveable.rememberSaveable
3130
import androidx.compose.ui.Modifier
3231
import com.firebase.ui.auth.AuthException
@@ -180,15 +179,15 @@ fun PhoneAuthScreen(
180179
}
181180
}
182181

183-
val authState by remember(authUI) { authUI.authStateFlow() }.collectAsState(AuthState.Idle)
182+
val currentAuthState = remember(authUI) { authUI.authStateFlow() }.collectAsState(AuthState.Idle)
183+
val authState by currentAuthState
184184
val isLoading = authState is AuthState.Loading
185185

186-
// A cancelled attempt leaves its Loading behind, and that state outlives this composition on
187-
// the process-scoped FirebaseAuthUI, so a freshly composed screen would inherit the spinner.
188-
val currentAuthState by rememberUpdatedState(authState)
186+
// A cancelled Loading outlives this composition on the process-scoped FirebaseAuthUI, and
187+
// currentAuthState is re-remembered per authUI, so onDispose reads the right instance.
189188
DisposableEffect(authUI) {
190189
onDispose {
191-
if (currentAuthState is AuthState.Loading) {
190+
if (currentAuthState.value is AuthState.Loading) {
192191
authUI.updateAuthState(AuthState.Idle)
193192
}
194193
}

0 commit comments

Comments
 (0)