Skip to content

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

Only show skip button during skippable phases (#520)

Leendert de Borst5164c705c28d
diff --git a/apps/mobile-app/app/initialize.tsx b/apps/mobile-app/app/initialize.tsx
index 80a6deae6..34ebcee4a 100644
--- a/apps/mobile-app/app/initialize.tsx
+++ b/apps/mobile-app/app/initialize.tsx
@@ -23,6 +23,7 @@ export default function Initialize() : React.ReactNode {
const hasInitialized = useRef(false);
const skipButtonTimeoutRef = useRef<NodeJS.Timeout | null>(null);
const lastStatusRef = useRef<string>('');
+ const canShowSkipButtonRef = useRef(false); // Only allow skip button after vault unlock
const { t } = useTranslation();
const app = useApp();
const { syncVault } = useVaultSync();
@@ -51,8 +52,8 @@ export default function Initialize() : React.ReactNode {
setShowSkipButton(false);
lastStatusRef.current = message;
- // Start new timer for the new status
- if (message) {
+ // Start new timer for the new status (only if skip button is allowed)
+ if (message && canShowSkipButtonRef.current) {
skipButtonTimeoutRef.current = setTimeout(() => {
setShowSkipButton(true);
}, 5000) as unknown as NodeJS.Timeout;
@@ -169,60 +170,55 @@ export default function Initialize() : React.ReactNode {
*/
const initializeApp = async () : Promise<void> => {
/**
- * Handle vault unlocking process.
+ * Initialize the app.
*/
- async function handleVaultUnlock() : Promise<void> {
- const { enabledAuthMethods } = await app.initializeAuth();
+ const initialize = async () : Promise<void> => {
+ const { isLoggedIn, enabledAuthMethods } = await app.initializeAuth();
+ if (!isLoggedIn) {
+ router.replace('/login');
+ return;
+ }
+
+ // Check if we have an encrypted database and if FaceID is enabled
try {
const hasEncryptedDatabase = await NativeVaultManager.hasEncryptedDatabase();
+
if (hasEncryptedDatabase) {
const isFaceIDEnabled = enabledAuthMethods.includes('faceid');
- if (!isFaceIDEnabled) {
- router.replace('/unlock');
- return;
- }
- updateStatus(t('app.status.unlockingVault'));
- const isUnlocked = await dbContext.unlockVault();
- if (isUnlocked) {
+ // Only attempt to unlock if FaceID is enabled
+ if (isFaceIDEnabled) {
+ // Unlock vault FIRST (before network sync) - this is not skippable
+ updateStatus(t('app.status.unlockingVault'));
+ const isUnlocked = await dbContext.unlockVault();
+
+ if (!isUnlocked) {
+ // Failed to unlock, redirect to unlock screen
+ router.replace('/unlock');
+ return;
+ }
+
+ // Add small delay for UX
await new Promise(resolve => setTimeout(resolve, 500));
- // Check if the vault is up to date, if not, redirect to the upgrade page.
+ // Check if the vault needs migration before syncing
if (await dbContext.hasPendingMigrations()) {
router.replace('/upgrade');
return;
}
- router.replace('/(tabs)/credentials');
- return;
+ // Vault unlocked successfully - now allow skip button for network operations
+ canShowSkipButtonRef.current = true;
}
-
- router.replace('/unlock');
- return;
- } else {
- router.replace('/unlock');
- return;
}
} catch (err) {
- console.error('Error during vault unlock:', err);
+ console.error('Error during initial vault unlock:', err);
router.replace('/unlock');
return;
}
- }
-
- /**
- * Initialize the app.
- */
- const initialize = async () : Promise<void> => {
- const { isLoggedIn } = await app.initializeAuth();
-
- if (!isLoggedIn) {
- router.replace('/login');
- return;
- }
- // First perform vault sync
+ // Now perform vault sync (network operations - these are skippable)
await syncVault({
initialSync: true,
/**
@@ -232,11 +228,11 @@ export default function Initialize() : React.ReactNode {
updateStatus(message);
},
/**
- * Handle successful vault sync and continue with vault unlock flow.
+ * Handle successful vault sync.
*/
onSuccess: async () => {
- // Continue with the rest of the flow after successful sync
- handleVaultUnlock();
+ // Vault already unlocked, just navigate to credentials
+ router.replace('/(tabs)/credentials');
},
/**
* Handle offline state and prompt user for action.
diff --git a/apps/mobile-app/app/reinitialize.tsx b/apps/mobile-app/app/reinitialize.tsx
index 5fcd04455..22ae49625 100644
--- a/apps/mobile-app/app/reinitialize.tsx
+++ b/apps/mobile-app/app/reinitialize.tsx
@@ -27,6 +27,7 @@ export default function ReinitializeScreen() : React.ReactNode {
const hasInitialized = useRef(false);
const skipButtonTimeoutRef = useRef<NodeJS.Timeout | null>(null);
const lastStatusRef = useRef<string>('');
+ const canShowSkipButtonRef = useRef(false); // Only allow skip button after vault unlock
const colors = useColors();
const { t } = useTranslation();
@@ -52,8 +53,8 @@ export default function ReinitializeScreen() : React.ReactNode {
setShowSkipButton(false);
lastStatusRef.current = message;
- // Start new timer for the new status
- if (message) {
+ // Start new timer for the new status (only if skip button is allowed)
+ if (message && canShowSkipButtonRef.current) {
skipButtonTimeoutRef.current = setTimeout(() => {
setShowSkipButton(true);
}, 5000) as unknown as NodeJS.Timeout;
@@ -238,64 +239,72 @@ export default function ReinitializeScreen() : React.ReactNode {
}
/**
- * Handle vault unlocking process.
+ * Initialize the app.
*/
- async function handleVaultUnlock() : Promise<void> {
- const { enabledAuthMethods } = await app.initializeAuth();
+ const initialize = async () : Promise<void> => {
+ const { isLoggedIn, enabledAuthMethods } = await app.initializeAuth();
+
+ // If user is not logged in, navigate to login immediately
+ if (!isLoggedIn) {
+ router.replace('/login');
+ return;
+ }
+
+ // If we already have an unlocked vault, we can skip the sync and go straight to the credentials screen
+ if (await NativeVaultManager.isVaultUnlocked()) {
+ redirectToReturnUrl();
+ return;
+ }
+ // Check if we have an encrypted database and if FaceID is enabled
try {
const hasEncryptedDatabase = await NativeVaultManager.hasEncryptedDatabase();
+
if (hasEncryptedDatabase) {
const isFaceIDEnabled = enabledAuthMethods.includes('faceid');
- if (!isFaceIDEnabled) {
- router.replace('/unlock');
- return;
- }
- updateStatus(t('app.status.unlockingVault'));
- const isUnlocked = await dbContext.unlockVault();
- if (isUnlocked) {
+ // Only attempt to unlock if FaceID is enabled
+ if (isFaceIDEnabled) {
+ // Unlock vault FIRST (before network sync) - this is not skippable
+ updateStatus(t('app.status.unlockingVault'));
+ const isUnlocked = await dbContext.unlockVault();
+
+ if (!isUnlocked) {
+ // Failed to unlock, redirect to unlock screen
+ router.replace('/unlock');
+ return;
+ }
+
+ // Add small delay for UX
await new Promise(resolve => setTimeout(resolve, 1000));
updateStatus(t('app.status.decryptingVault'));
await new Promise(resolve => setTimeout(resolve, 1000));
- // Check if the vault is up to date, if not, redirect to the upgrade page.
+ // Check if the vault needs migration before syncing
if (await dbContext.hasPendingMigrations()) {
router.replace('/upgrade');
return;
}
- redirectToReturnUrl();
+ // Vault unlocked successfully - now allow skip button for network operations
+ canShowSkipButtonRef.current = true;
+ } else {
+ // No FaceID, redirect to unlock screen
+ router.replace('/unlock');
return;
}
+ } else {
+ // No encrypted database, redirect to unlock screen
+ router.replace('/unlock');
+ return;
}
-
- router.replace('/unlock');
} catch (err) {
- console.error('Error during vault unlock:', err);
+ console.error('Error during initial vault unlock:', err);
router.replace('/unlock');
- }
- }
-
- /**
- * Initialize the app.
- */
- const initialize = async () : Promise<void> => {
- const { isLoggedIn } = await app.initializeAuth();
-
- // If user is not logged in, navigate to login immediately
- if (!isLoggedIn) {
- router.replace('/login');
- return;
- }
-
- // If we already have an unlocked vault, we can skip the sync and go straight to the credentials screen
- if (await NativeVaultManager.isVaultUnlocked()) {
- router.replace('/(tabs)/credentials');
return;
}
- // First perform vault sync
+ // Now perform vault sync (network operations - these are skippable)
await syncVault({
initialSync: true,
/**
@@ -305,10 +314,11 @@ export default function ReinitializeScreen() : React.ReactNode {
updateStatus(message);
},
/**
- * Handle successful vault sync and continue with vault unlock flow.
+ * Handle successful vault sync.
*/
onSuccess: async () => {
- await handleVaultUnlock();
+ // Vault already unlocked, just navigate to return URL
+ redirectToReturnUrl();
},
/**
* Handle error during vault sync.
@@ -316,8 +326,8 @@ export default function ReinitializeScreen() : React.ReactNode {
*/
onError: (error: string) => {
console.error('Vault sync error during reinitialize:', error);
- // Even if sync fails, try to continue with local vault if available
- handleVaultUnlock();
+ // Even if sync fails, vault is already unlocked, so navigate to return URL
+ redirectToReturnUrl();
},
/**
* Handle offline state and prompt user for action.