Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.
Do not block passkey creation when server is unreachable (#2180)
Leendert de Borst8d3f8662f164
diff --git a/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/credentialprovider/PasskeyFormFragment.kt b/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/credentialprovider/PasskeyFormFragment.ktindex a6b625376..03865ea29 100644--- a/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/credentialprovider/PasskeyFormFragment.kt+++ b/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/credentialprovider/PasskeyFormFragment.kt@@ -15,10 +15,11 @@ import androidx.fragment.app.activityViewModelsimport androidx.lifecycle.lifecycleScopeimport com.google.android.material.button.MaterialButtonimport com.google.android.material.textfield.TextInputEditText+import kotlinx.coroutines.CancellationExceptionimport kotlinx.coroutines.Dispatchers-import kotlinx.coroutines.delayimport kotlinx.coroutines.launchimport kotlinx.coroutines.withContext+import kotlinx.coroutines.withTimeoutOrNullimport net.aliasvault.app.Rimport net.aliasvault.app.components.LoadingIndicatorimport net.aliasvault.app.credentialprovider.models.PasskeyRegistrationViewModel@@ -47,6 +48,13 @@ class PasskeyFormFragment : Fragment() {private const val ARG_PASSKEY_ID = "passkey_id"private const val ARG_ITEM_ID = "item_id"+ /**+ * Maximum time to wait for a best-effort server sync/upload before proceeding offline.+ * Keeps passkey creation responsive when the server is slow or unreachable; the passkey is+ * always stored locally and the vault stays dirty, so it syncs on the next opportunity.+ */+ private const val BEST_EFFORT_SYNC_TIMEOUT_MS = 5000L+/*** Create a new instance of PasskeyFormFragment.*@@ -247,8 +255,14 @@ class PasskeyFormFragment : Fragment() {showLoading(getString(R.string.passkey_checking_connection))}- val syncResult = vaultStore.syncVaultWithServer(webApiService)- if (!syncResult.success && !syncResult.wasOffline) {+ // Best-effort sync: try immediately so the passkey is persisted to the local vault,+ // but do not block the passkey creation flow itself if server is not available.+ val syncResult = withTimeoutOrNull(BEST_EFFORT_SYNC_TIMEOUT_MS) {+ vaultStore.syncVaultWithServer(webApiService)+ }+ // Only surface a fast, definitive failure (e.g. session expired or password changed).+ // A timeout (null) or an offline result is treated as best-effort: continue locally.+ if (syncResult != null && !syncResult.success && !syncResult.wasOffline) {// Server connectivity check failed - show appropriate error dialogwithContext(Dispatchers.Main) {showSyncErrorAlert(Exception(syncResult.error ?: "Sync failed"))@@ -339,14 +353,15 @@ class PasskeyFormFragment : Fragment() {showLoading(getString(R.string.passkey_syncing))}- try {- vaultStore.mutateVault(webApiService)- } catch (e: Exception) {- Log.w(TAG, "Vault mutation failed, but passkey was created locally", e)- // Show error dialog but continue - passkey is still saved locally- withContext(Dispatchers.Main) {- showSyncErrorAlert(e)- delay(2000)+ // Best-effort sync: try immediately so the passkey is persisted to the local vault,+ // but do not block the passkey creation flow itself if server is not available.+ withTimeoutOrNull(BEST_EFFORT_SYNC_TIMEOUT_MS) {+ try {+ vaultStore.mutateVault(webApiService)+ } catch (e: CancellationException) {+ throw e+ } catch (e: Exception) {+ Log.w(TAG, "Vault mutation failed, but passkey was created locally", e)}}@@ -445,8 +460,14 @@ class PasskeyFormFragment : Fragment() {showLoading(getString(R.string.passkey_checking_connection))}- val syncResult = vaultStore.syncVaultWithServer(webApiService)- if (!syncResult.success && !syncResult.wasOffline) {+ // Best-effort sync: try immediately so the passkey is persisted to the local vault,+ // but do not block the passkey creation flow itself if server is not available.+ val syncResult = withTimeoutOrNull(BEST_EFFORT_SYNC_TIMEOUT_MS) {+ vaultStore.syncVaultWithServer(webApiService)+ }+ // Only surface a fast, definitive failure (e.g. session expired or password changed).+ // A timeout (null) or an offline result is treated as best-effort: continue locally.+ if (syncResult != null && !syncResult.success && !syncResult.wasOffline) {// Server connectivity check failed - show appropriate error dialogwithContext(Dispatchers.Main) {showSyncErrorAlert(Exception(syncResult.error ?: "Sync failed"))@@ -534,14 +555,15 @@ class PasskeyFormFragment : Fragment() {showLoading(getString(R.string.passkey_syncing))}- try {- vaultStore.mutateVault(webApiService)- } catch (e: Exception) {- Log.w(TAG, "Vault mutation failed, but passkey was replaced locally", e)- // Show error dialog but continue - passkey is still saved locally- withContext(Dispatchers.Main) {- showSyncErrorAlert(e)- delay(2000)+ // Best-effort sync: try immediately so the passkey is persisted to the local vault,+ // but do not block the passkey creation flow itself if server is not available.+ withTimeoutOrNull(BEST_EFFORT_SYNC_TIMEOUT_MS) {+ try {+ vaultStore.mutateVault(webApiService)+ } catch (e: CancellationException) {+ throw e+ } catch (e: Exception) {+ Log.w(TAG, "Vault mutation failed, but passkey was replaced locally", e)}}@@ -645,8 +667,16 @@ class PasskeyFormFragment : Fragment() {showLoading(getString(R.string.passkey_checking_connection))}- val syncResult = vaultStore.syncVaultWithServer(webApiService)- if (!syncResult.success && !syncResult.wasOffline) {+ // Best-effort sync: try immediately so the passkey is created on top of the latest+ // vault, but never let a slow or unreachable server block the user. If it doesn't+ // finish within the timeout we proceed offline (the passkey is stored locally and the+ // vault stays dirty, so it syncs on the next opportunity).+ val syncResult = withTimeoutOrNull(BEST_EFFORT_SYNC_TIMEOUT_MS) {+ vaultStore.syncVaultWithServer(webApiService)+ }+ // Only surface a fast, definitive failure (e.g. session expired or password changed).+ // A timeout (null) or an offline result is treated as best-effort: continue locally.+ if (syncResult != null && !syncResult.success && !syncResult.wasOffline) {// Server connectivity check failed - show appropriate error dialogwithContext(Dispatchers.Main) {showSyncErrorAlert(Exception(syncResult.error ?: "Sync failed"))@@ -733,14 +763,16 @@ class PasskeyFormFragment : Fragment() {showLoading(getString(R.string.passkey_syncing))}- try {- vaultStore.mutateVault(webApiService)- } catch (e: Exception) {- Log.w(TAG, "Vault mutation failed, but passkey was added locally", e)- // Show error dialog but continue - passkey is still saved locally- withContext(Dispatchers.Main) {- showSyncErrorAlert(e)- delay(2000)+ // Best-effort upload bounded by the same timeout so a slow server can't hang the+ // overlay. On timeout or failure the passkey stays saved locally with the vault marked+ // dirty and syncs on the next opportunity.+ withTimeoutOrNull(BEST_EFFORT_SYNC_TIMEOUT_MS) {+ try {+ vaultStore.mutateVault(webApiService)+ } catch (e: CancellationException) {+ throw e+ } catch (e: Exception) {+ Log.w(TAG, "Vault mutation failed, but passkey was added locally", e)}}