diff --git a/app/src/main/java/com/x8bit/bitwarden/data/autofill/fido2/processor/Fido2ProviderProcessorImpl.kt b/app/src/main/java/com/x8bit/bitwarden/data/autofill/fido2/processor/Fido2ProviderProcessorImpl.kt index 851cf1f58..777c9ffb1 100644 --- a/app/src/main/java/com/x8bit/bitwarden/data/autofill/fido2/processor/Fido2ProviderProcessorImpl.kt +++ b/app/src/main/java/com/x8bit/bitwarden/data/autofill/fido2/processor/Fido2ProviderProcessorImpl.kt @@ -25,7 +25,6 @@ import com.x8bit.bitwarden.data.auth.repository.model.UserState import com.x8bit.bitwarden.data.platform.manager.dispatcher.DispatcherManager import com.x8bit.bitwarden.ui.platform.manager.intent.IntentManager import kotlinx.coroutines.CoroutineScope -import kotlinx.coroutines.cancel import kotlinx.coroutines.launch import java.util.concurrent.atomic.AtomicInteger @@ -51,22 +50,23 @@ class Fido2ProviderProcessorImpl( cancellationSignal: CancellationSignal, callback: OutcomeReceiver, ) { - cancellationSignal.setOnCancelListener { - callback.onError(CreateCredentialCancellationException()) - scope.cancel() - } - val userId = authRepository.activeUserId if (userId == null) { callback.onError(CreateCredentialUnknownException("Active user is required.")) return } - scope.launch { + val createCredentialJob = scope.launch { processCreateCredentialRequest(request = request) ?.let { callback.onResult(it) } ?: callback.onError(CreateCredentialUnknownException()) } + cancellationSignal.setOnCancelListener { + if (createCredentialJob.isActive) { + createCredentialJob.cancel() + } + callback.onError(CreateCredentialCancellationException()) + } } private fun processCreateCredentialRequest(