@@ -414,7 +414,10 @@ internal class AuthenticatorViewModel(
414414 return
415415 }
416416
417- var updatedInfo = info.copy(selectedAuthFactor = null )
417+ // Use has not selected an auth factor yet.
418+ // We need to keep track of a mutating selection here as `onSelect` may be called multiple times as user
419+ // retries after encountering an error (e.g. incorrect password, passkey error, etc).
420+ var currentUserInfo = info.copy(selectedAuthFactor = null )
418421
419422 val newState = stateFactory.newSignInSelectFactorState(
420423 username = info.username,
@@ -427,14 +430,18 @@ internal class AuthenticatorViewModel(
427430 null
428431 }
429432
430- if (updatedInfo.selectedAuthFactor != null ) {
431- // User has already selected an auth factor so we need to restart the flow over
432- updatedInfo = info.copy(selectedAuthFactor = authFactor)
433- startSignIn(updatedInfo, preferredFirstFactorOverride = authFactor)
433+ // If a user has already previously selected an auth factor then we need to restart the sign in
434+ // flow in order to select a factor again.
435+ val flowRestartRequired = currentUserInfo.selectedAuthFactor != null
436+
437+ currentUserInfo = info.copy(password = password, selectedAuthFactor = authFactor)
438+
439+ if (flowRestartRequired) {
440+ // Call signIn to restart the flow but select the same factor
441+ startSignIn(currentUserInfo, preferredFirstFactorOverride = authFactor)
434442 } else {
435443 // Use confirmSignIn to select an auth factor for the first time
436- updatedInfo = info.copy(password = password, selectedAuthFactor = authFactor)
437- confirmSignIn(updatedInfo, authFactor.challengeResponse)
444+ confirmSignIn(currentUserInfo, authFactor.challengeResponse)
438445 }
439446 }
440447 )
0 commit comments