From b1b4d7bff7d9adece47c25bd9ffe019f0df9ebd3 Mon Sep 17 00:00:00 2001 From: Leendert de Borst Date: Thu, 24 Apr 2025 16:37:15 +0200 Subject: [PATCH] Make vault decryption catch and print errors (#771) --- .../src/entrypoints/popup/pages/CredentialsList.tsx | 11 +++++++++-- mobile-app/hooks/useVaultSync.ts | 10 +++++++--- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/browser-extension/src/entrypoints/popup/pages/CredentialsList.tsx b/browser-extension/src/entrypoints/popup/pages/CredentialsList.tsx index fedab7658..b2100fec0 100644 --- a/browser-extension/src/entrypoints/popup/pages/CredentialsList.tsx +++ b/browser-extension/src/entrypoints/popup/pages/CredentialsList.tsx @@ -66,8 +66,15 @@ const CredentialsList: React.FC = () => { // Get derived key from background worker const passwordHashBase64 = await sendMessage('GET_DERIVED_KEY', {}, 'background') as string; - // Initialize the SQLite context again with the newly retrieved decrypted blob - await dbContext.initializeDatabase(vaultResponseJson, passwordHashBase64); + // Initialize the SQLite context again with the newly retrieved decrypted blob) + try { + await dbContext.initializeDatabase(vaultResponseJson, passwordHashBase64); + } catch (err) { + // If error occurs during database initialization, it most likely has to do with decryption that + // failed. This is most likely due to the user changing their password. + // So we logout the user here to force them to re-authenticate. + await webApi.logout('Vault could not be decrypted, please re-authenticate.'); + } } catch (err) { console.error('Refresh error:', err); } diff --git a/mobile-app/hooks/useVaultSync.ts b/mobile-app/hooks/useVaultSync.ts index 36e86253a..e3ce7e7fa 100644 --- a/mobile-app/hooks/useVaultSync.ts +++ b/mobile-app/hooks/useVaultSync.ts @@ -93,9 +93,13 @@ export const useVaultSync = () => { } console.log('Re-initializing database with new vault'); - dbContext.initializeDatabase(vaultResponseJson as VaultResponse, null); - onSuccess?.(true); - return true; + try { + await dbContext.initializeDatabase(vaultResponseJson as VaultResponse, null); + onSuccess?.(true); + return true; + } catch (err) { + throw new Error('Vault could not be decrypted, if problem persists please logout and login again.'); + } } console.log('Vault sync finished: No updates needed');