Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.
Add initial credential identity store sync for iOS if store is empty (#520)
Leendert de Borst9ec245c102af
diff --git a/apps/mobile-app/ios/Autofill/CredentialProviderViewController.swift b/apps/mobile-app/ios/Autofill/CredentialProviderViewController.swiftindex 233a4575d..7010e54bf 100644--- a/apps/mobile-app/ios/Autofill/CredentialProviderViewController.swift+++ b/apps/mobile-app/ios/Autofill/CredentialProviderViewController.swift@@ -195,6 +195,13 @@ public class CredentialProviderViewController: ASCredentialProviderViewControlleif currentHostingController == nil {do {try setupView(vaultStore: vaultStore)++ // Perform initial credential sync if the credential identity store is empty+ // This is an OOBE (Out Of Box Experience) step to populate the store on first use+ // Note: Regular syncs happen in the main app, this is just a fallback+ Task {+ await performInitialSyncIfNeeded(vaultStore: vaultStore)+ }} catch {print("Failed to setup view: \(error)")let alert = UIAlertController(@@ -351,6 +358,32 @@ public class CredentialProviderViewController: ASCredentialProviderViewControlle}}+ /// Perform initial sync if credential identity store is empty+ /// This is called on first autofill use as an OOBE step+ private func performInitialSyncIfNeeded(vaultStore: VaultStore) async {+ do {+ // Check if the credential identity store is empty+ let isEmpty = await CredentialIdentityStore.shared.isStoreEmpty()+ guard isEmpty else {+ print("Credential identity store already has entries, skipping initial sync")+ return+ }++ print("Credential identity store is empty, performing initial sync")++ // Get all credentials from the vault (already unlocked)+ let credentials = try vaultStore.getAllCredentials()++ // Save credentials to the iOS credential identity store+ try await CredentialIdentityStore.shared.saveCredentialIdentities(credentials)++ print("Initial credential sync completed successfully")+ } catch {+ // Log error but don't block the user - they can still use autofill+ print("Initial credential sync failed: \(error)")+ }+ }+/// Run sanity checks on the vault store before opening the autofill view to check things like if user is logged in,/// vault is available etc./// - Returnsdiff --git a/apps/mobile-app/ios/VaultStoreKit/CredentialIdentityStore.swift b/apps/mobile-app/ios/VaultStoreKit/CredentialIdentityStore.swiftindex 3cf2b4852..f893b361d 100644--- a/apps/mobile-app/ios/VaultStoreKit/CredentialIdentityStore.swift+++ b/apps/mobile-app/ios/VaultStoreKit/CredentialIdentityStore.swift@@ -63,6 +63,13 @@ public class CredentialIdentityStore {}}+ /// Check if the credential identity store supports incremental updates and has credentials+ /// Returns true if the store is empty or doesn't support incremental updates+ public func isStoreEmpty() async -> Bool {+ let state = await storeState()+ return !state.supportsIncrementalUpdates+ }+private static func effectiveDomain(from host: String) -> String {let parts = host.split(separator: ".")guard parts.count >= 2 else { return host }