Make vault decryption catch and print errors (#771)

This commit is contained in:
Leendert de Borst
2025-04-24 16:37:15 +02:00
parent d4a39caa22
commit b1b4d7bff7
2 changed files with 16 additions and 5 deletions

View File

@@ -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);
}

View File

@@ -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');