Skip to content

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

Add transaction commit to credential delete (#771)

Leendert de Borst06a5c5035990
diff --git a/apps/mobile-app/app/(tabs)/credentials/add-edit.tsx b/apps/mobile-app/app/(tabs)/credentials/add-edit.tsx
index 919df57d2..590d152ed 100644
--- a/apps/mobile-app/app/(tabs)/credentials/add-edit.tsx
+++ b/apps/mobile-app/app/(tabs)/credentials/add-edit.tsx
@@ -280,7 +280,7 @@ export default function AddEditCredentialScreen() {
NickName: identity.nickName,
BirthDate: IdentityHelperUtils.normalizeBirthDateForDisplay(identity.birthDate.toISOString()),
Gender: identity.gender,
- Email: identity.emailPrefix
+ Email: email
}
};
};
@@ -369,7 +369,9 @@ export default function AddEditCredentialScreen() {
onPress: async () => {
await executeVaultMutation(async () => {
+ console.log('Starting delete operation');
await dbContext.sqliteClient!.deleteCredentialById(id);
+ console.log('Credential deleted successfully');
});
// Show success toast
diff --git a/apps/mobile-app/hooks/useVaultMutate.ts b/apps/mobile-app/hooks/useVaultMutate.ts
index 99d583abc..906329596 100644
--- a/apps/mobile-app/hooks/useVaultMutate.ts
+++ b/apps/mobile-app/hooks/useVaultMutate.ts
@@ -5,9 +5,6 @@ import { useWebApi } from '@/context/WebApiContext';
import { useVaultSync } from './useVaultSync';
import NativeVaultManager from '@/specs/NativeVaultManager';
import Toast from 'react-native-toast-message';
-import emitter from '@/utils/EventEmitter';
-import { Credential } from '@/utils/types/Credential';
-import { FaviconExtractModel } from '@/utils/types/webapi/FaviconExtractModel';
interface VaultPostResponse {
status: number;
@@ -81,6 +78,7 @@ export function useVaultMutate() {
const currentRevision = await NativeVaultManager.getCurrentVaultRevisionNumber();
// Get the encrypted database
+ console.log('Getting encrypted database new version');
const encryptedDb = await NativeVaultManager.getEncryptedDatabase();
if (!encryptedDb) {
throw new Error('Failed to get encrypted database');
@@ -132,31 +130,9 @@ export function useVaultMutate() {
}
};
- const deleteCredential = useCallback(async (
- credentialId: string,
- options: VaultMutationOptions = {}
- ) => {
- await executeVaultMutation(async () => {
- await dbContext.sqliteClient!.deleteCredentialById(credentialId);
-
- // Emit an event to notify list and detail views to refresh
- emitter.emit('credentialChanged', credentialId);
-
- // Show success toast
- setTimeout(() => {
- Toast.show({
- type: 'success',
- text1: 'Credential deleted successfully',
- position: 'bottom'
- });
- }, 200);
- }, options);
- }, [executeVaultMutation, dbContext]);
-
return {
executeVaultMutation,
isLoading,
- syncStatus,
- deleteCredential
+ syncStatus
};
}
diff --git a/apps/mobile-app/utils/SqliteClient.tsx b/apps/mobile-app/utils/SqliteClient.tsx
index 2e4b856a7..5609a13ff 100644
--- a/apps/mobile-app/utils/SqliteClient.tsx
+++ b/apps/mobile-app/utils/SqliteClient.tsx
@@ -274,7 +274,10 @@ class SqliteClient {
* @param credentialId - The ID of the credential to delete
* @returns The number of rows deleted
*/
- public async deleteCredentialById(credentialId: string): Promise<number> {
+ public async deleteCredentialById(credentialId: string): Promise<number> {
+ try {
+ await NativeVaultManager.beginTransaction();
+
const currentDateTime = new Date().toISOString()
.replace('T', ' ')
.replace('Z', '')
@@ -311,7 +314,13 @@ class SqliteClient {
await this.executeUpdate(aliasQuery, [currentDateTime, credentialId]);
await this.executeUpdate(serviceQuery, [currentDateTime, credentialId]);
+ await NativeVaultManager.commitTransaction();
return results;
+ } catch (error) {
+ await NativeVaultManager.rollbackTransaction();
+ console.error('Error deleting credential:', error);
+ throw error;
+ }
}
/**