Skip to content

Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.

Simplify pin unlock reject flow (#1340)

Leendert de Borst563941f91359
diff --git a/apps/mobile-app/app/unlock.tsx b/apps/mobile-app/app/unlock.tsx
index 84f4f3a28..d2c948ce1 100644
--- a/apps/mobile-app/app/unlock.tsx
+++ b/apps/mobile-app/app/unlock.tsx
@@ -30,7 +30,7 @@ export default function UnlockScreen() : React.ReactNode {
const { isLoggedIn, username, isBiometricsEnabled, getBiometricDisplayNameKey, getEncryptionKeyDerivationParams, logout } = useApp();
const dbContext = useDb();
const [password, setPassword] = useState('');
- const [isLoading, setIsLoading] = useState(false);
+ const [isLoading, setIsLoading] = useState(true);
const [isBiometricsAvailable, setIsBiometricsAvailable] = useState(false);
const colors = useColors();
const { t } = useTranslation();
@@ -100,7 +100,12 @@ export default function UnlockScreen() : React.ReactNode {
if (err && typeof err === 'object' && 'code' in err) {
const error = err as { code?: string; message?: string };
if (error.code === 'USER_CANCELLED') {
- // User cancelled PIN entry - show password input as fallback
+ /*
+ * User cancelled PIN entry or PIN was disabled
+ * Check if PIN is still available and update state accordingly
+ */
+ const pinStillEnabled = await isPinEnabled();
+ setPinAvailable(pinStillEnabled);
return;
} else if (error.code === 'NOT_IMPLEMENTED') {
/*
@@ -113,14 +118,6 @@ export default function UnlockScreen() : React.ReactNode {
[{ text: t('common.ok'), style: 'default' }]
);
return;
- } else if (error.code === 'PIN_DISABLED') {
- // PIN was disabled due to too many attempts
- setPinAvailable(false);
- Alert.alert(
- t('common.error'),
- t('settings.vaultUnlockSettings.pinLocked'),
- [{ text: t('common.ok'), style: 'default' }]
- );
} else {
// Other errors - show password input as fallback
console.error('PIN unlock failed:', err);
@@ -157,10 +154,11 @@ export default function UnlockScreen() : React.ReactNode {
* If user cancels or PIN is not available, loading stops and password input shows
*/
if (pinEnabled) {
- setIsLoading(true);
await handlePinUnlock();
+ } else {
+ // No PIN available, stop loading to show password input
+ setIsLoading(false);
}
- // If no PIN, isLoading stays false and password input shows automatically
};
fetchConfigAndUnlock();
diff --git a/apps/mobile-app/ios/Autofill/CredentialProviderViewController.swift b/apps/mobile-app/ios/Autofill/CredentialProviderViewController.swift
index dc35236f2..c0414a3e7 100644
--- a/apps/mobile-app/ios/Autofill/CredentialProviderViewController.swift
+++ b/apps/mobile-app/ios/Autofill/CredentialProviderViewController.swift
@@ -235,36 +235,9 @@ public class CredentialProviderViewController: ASCredentialProviderViewControlle
}
}
},
- cancelHandler: { [weak self] pinWasDisabled in
- guard let self = self else { return }
-
- if pinWasDisabled {
- // PIN was disabled due to max attempts
- // Try biometric as fallback if available
- if vaultStore.isBiometricAuthEnabled() {
- do {
- // Try to unlock with biometric
- try vaultStore.unlockVault()
-
- // Success - process the credential request
- if let passkeyRequest = self.quickReturnPasskeyRequest {
- self.handleQuickReturnPasskeyCredential(vaultStore: vaultStore, request: passkeyRequest)
- } else if let passwordRequest = self.quickReturnPasswordRequest {
- self.handleQuickReturnPasswordCredential(vaultStore: vaultStore, request: passwordRequest)
- }
- } catch {
- // Biometric failed - cancel
- print("Biometric fallback failed after PIN lockout: \(error)")
- self.handleCancel()
- }
- } else {
- // No other auth method - cancel
- self.handleCancel()
- }
- } else {
- // User manually cancelled
- self.handleCancel()
- }
+ cancelHandler: { [weak self] in
+ // User cancelled or PIN was disabled - just cancel
+ self?.handleCancel()
}
)
diff --git a/apps/mobile-app/ios/Autofill/UnlockCoordinator.swift b/apps/mobile-app/ios/Autofill/UnlockCoordinator.swift
index 1f307e585..b9f30f185 100644
--- a/apps/mobile-app/ios/Autofill/UnlockCoordinator.swift
+++ b/apps/mobile-app/ios/Autofill/UnlockCoordinator.swift
@@ -100,24 +100,10 @@ class UnlockCoordinator: ObservableObject {
self.onUnlocked()
}
},
- cancelHandler: { [weak self] pinWasDisabled in
- guard let self = self else { return }
-
- if pinWasDisabled {
- // PIN was disabled due to max attempts
- // Try biometric as fallback if available
- if self.vaultStore.isBiometricAuthEnabled() {
- Task {
- await self.attemptBiometricUnlock()
- }
- } else {
- // No other auth method available - cancel
- self.cancel()
- }
- } else {
- // User manually cancelled - just cancel
- self.cancel()
- }
+ cancelHandler: { [weak self] in
+ // User cancelled or PIN was disabled
+ // Just cancel - let the system handle the fallback
+ self?.cancel()
}
)
}
diff --git a/apps/mobile-app/ios/NativeVaultManager/VaultManager.swift b/apps/mobile-app/ios/NativeVaultManager/VaultManager.swift
index 1d847038c..3dde91eca 100644
--- a/apps/mobile-app/ios/NativeVaultManager/VaultManager.swift
+++ b/apps/mobile-app/ios/NativeVaultManager/VaultManager.swift
@@ -859,16 +859,12 @@ public class VaultManager: NSObject {
}
}
},
- cancelHandler: { pinWasDisabled in
+ cancelHandler: {
// Dismiss the view
+ // No need to distinguish between user cancel vs PIN disabled
+ // React Native will check isPinEnabled() to update UI state
rootVC.dismiss(animated: true) {
- if pinWasDisabled {
- // PIN was disabled due to max attempts
- reject("PIN_DISABLED", "PIN was disabled after too many failed attempts", nil)
- } else {
- // User manually cancelled
- reject("USER_CANCELLED", "User cancelled PIN unlock", nil)
- }
+ reject("USER_CANCELLED", "User cancelled PIN unlock", nil)
}
}
)
diff --git a/apps/mobile-app/ios/VaultUI/Auth/PinUnlockView.swift b/apps/mobile-app/ios/VaultUI/Auth/PinUnlockView.swift
index 673a5e94f..22869b6cf 100644
--- a/apps/mobile-app/ios/VaultUI/Auth/PinUnlockView.swift
+++ b/apps/mobile-app/ios/VaultUI/Auth/PinUnlockView.swift
@@ -154,21 +154,15 @@ public struct PinUnlockView: View {
Color.black.opacity(0.3)
.ignoresSafeArea()
- VStack(spacing: 16) {
- ProgressView()
- .progressViewStyle(CircularProgressViewStyle(tint: theme.primary))
- .scaleEffect(1.5)
-
- Text(String(localized: "unlocking", bundle: locBundle))
- .font(.system(size: 16, weight: .medium))
- .foregroundColor(theme.text)
- }
- .padding(24)
- .background(
- RoundedRectangle(cornerRadius: 16)
- .fill(theme.accentBackground)
- )
- .shadow(color: Color.black.opacity(0.2), radius: 10, x: 0, y: 4)
+ ProgressView()
+ .progressViewStyle(CircularProgressViewStyle(tint: theme.primary))
+ .scaleEffect(1.5)
+ .padding(24)
+ .background(
+ RoundedRectangle(cornerRadius: 16)
+ .fill(theme.accentBackground)
+ )
+ .shadow(color: Color.black.opacity(0.2), radius: 10, x: 0, y: 4)
}
.transition(.opacity)
}
@@ -289,12 +283,12 @@ public class PinUnlockViewModel: ObservableObject {
public let pinLength: Int?
private let unlockHandler: (String) async throws -> Void
- private let cancelHandler: (Bool) -> Void // Bool indicates if PIN was disabled/locked
+ private let cancelHandler: () -> Void
public init(
pinLength: Int?,
unlockHandler: @escaping (String) async throws -> Void,
- cancelHandler: @escaping (Bool) -> Void
+ cancelHandler: @escaping () -> Void
) {
self.pinLength = pinLength
self.unlockHandler = unlockHandler
@@ -317,6 +311,8 @@ public class PinUnlockViewModel: ObservableObject {
if let expectedLength = pinLength, pin.count == expectedLength {
// Small delay to show the last dot filled before attempting unlock
Task {
+ // Wait for the UI to update with the last filled dot
+ try? await Task.sleep(nanoseconds: 100_000_000) // 100ms
await attemptUnlock()
}
}
@@ -329,26 +325,37 @@ public class PinUnlockViewModel: ObservableObject {
}
public func cancel() {
- cancelHandler(false) // User manually cancelled
+ cancelHandler()
}
private func attemptUnlock() async {
- // Show loading state
+ // Show loading state immediately before expensive Argon2 computation
isUnlocking = true
+ // Give the UI one more frame to show the loading state
+ try? await Task.sleep(nanoseconds: 50_000_000) // 50ms
+
do {
// Call the injected unlock handler with the PIN
+ // This will perform Argon2 key derivation which may take 500ms-1s
try await unlockHandler(pin)
// Success - the handler will navigate away or complete the flow
// Keep loading state active since we're navigating
} catch let nsError as NSError {
- // Check for PIN disabled errors (error code 25)
- // This occurs when PIN was disabled due to max attempts or configuration issue
- if nsError.code == 25 {
- // PIN is no longer available - auto-dismiss the view
- // This happens when user enters wrong PIN too many times
+ // Check for PIN disabled/locked errors (error codes 25 or 26)
+ // These occur when PIN was disabled due to max attempts or configuration issue
+ if nsError.code == 25 || nsError.code == 26 {
+ // Show the error message briefly before auto-dismissing
isUnlocking = false
- cancelHandler(true)
+ self.error = nsError.localizedDescription
+ triggerErrorFeedback()
+
+ // Wait to let user see the error message
+ try? await Task.sleep(nanoseconds: 1_000_000_000) // 1 second
+
+ // Clear the error and dismiss
+ self.error = nil
+ cancelHandler()
return
}