forked from trent_larson/crowd-funder-for-time-pwa
feat: add duplicate account import prevention
- Add duplicate check in ImportAccountView before account import - Add duplicate check in ImportDerivedAccountView for derived accounts - Add safety check in saveNewIdentity function to prevent duplicate saves - Implement user-friendly warning messages for duplicate attempts - Add comprehensive error handling to catch duplicate errors from saveNewIdentity - Create Playwright tests to verify duplicate prevention functionality - Add documentation for duplicate prevention implementation The system now prevents users from importing the same account multiple times by checking for existing DIDs both before import (pre-check) and during save (post-check). Users receive clear warning messages instead of technical errors when attempting to import duplicate accounts. Files modified: - src/views/ImportAccountView.vue: Add duplicate check and error handling - src/views/ImportDerivedAccountView.vue: Add duplicate check for derived accounts - src/libs/util.ts: Add duplicate prevention in saveNewIdentity - test-playwright/duplicate-import-test.spec.ts: Add comprehensive tests - doc/duplicate-account-import-implementation.md: Add implementation docs Resolves: Prevent duplicate account imports in IdentitySwitcherView
This commit is contained in:
@@ -626,6 +626,18 @@ export async function saveNewIdentity(
|
||||
// add to the new sql db
|
||||
const platformService = await getPlatformService();
|
||||
|
||||
// Check if account already exists before attempting to save
|
||||
const existingAccount = await platformService.dbQuery(
|
||||
"SELECT did FROM accounts WHERE did = ?",
|
||||
[identity.did],
|
||||
);
|
||||
|
||||
if (existingAccount?.values?.length) {
|
||||
throw new Error(
|
||||
`Account with DID ${identity.did} already exists. Cannot import duplicate account.`,
|
||||
);
|
||||
}
|
||||
|
||||
const secrets = await platformService.dbQuery(
|
||||
`SELECT secretBase64 FROM secret`,
|
||||
);
|
||||
@@ -660,10 +672,8 @@ export async function saveNewIdentity(
|
||||
|
||||
await platformService.insertNewDidIntoSettings(identity.did);
|
||||
} catch (error) {
|
||||
logger.error("Failed to update default settings:", error);
|
||||
throw new Error(
|
||||
"Failed to set default settings. Please try again or restart the app.",
|
||||
);
|
||||
logger.error("Failed to save new identity:", error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user