From 76cfd93c573a6c7dd00232058fdb0150903c2a12 Mon Sep 17 00:00:00 2001 From: Sara Tavares <29093946+stavares843@users.noreply.github.com> Date: Mon, 11 Nov 2024 15:51:30 +0000 Subject: [PATCH] chore(profile): delete account (#826) --- src/lib/lang/en.json | 2 + src/routes/settings/profile/+page.svelte | 76 ++++++++++++++++++++++++ 2 files changed, 78 insertions(+) diff --git a/src/lib/lang/en.json b/src/lib/lang/en.json index d0412b438..5d2094be5 100644 --- a/src/lib/lang/en.json +++ b/src/lib/lang/en.json @@ -323,6 +323,8 @@ "label": "Log Out", "description": "Log out of the current account and return to the unlock page." }, + "delete_title": "Delete Account", + "delete_subtitle": "Click here to delete your account", "change_profile_photo": "Change profile photo", "reveal_phrase": { "label": "Reveal recovery phrase", diff --git a/src/routes/settings/profile/+page.svelte b/src/routes/settings/profile/+page.svelte index 8b57b2fef..78f03f76a 100644 --- a/src/routes/settings/profile/+page.svelte +++ b/src/routes/settings/profile/+page.svelte @@ -100,6 +100,69 @@ isValidUsernameToUpdate = false } +// Function to delete IndexedDB database by name +function deleteIndexedDB(dbName) { + return new Promise((resolve, reject) => { + const request = indexedDB.deleteDatabase(dbName) + + request.onsuccess = function () { + console.log(`Database '${dbName}' deleted successfully.`) + resolve() + } + + request.onerror = function () { + console.error(`Failed to delete database '${dbName}':`, request.error) + reject(request.error) + } + + request.onblocked = function () { + console.warn(`Database deletion for '${dbName}' is blocked. Close other tabs that use it and try again.`) + // Continue even if blocked, but mark as incomplete + resolve('Blocked') + } + }) +} + +// Function to clear all IndexedDB data, localStorage, sessionStorage, and cookies +async function clearAllData() { + try { + // Clear localStorage and sessionStorage first + localStorage.clear() + console.log("localStorage cleared.") + + sessionStorage.clear() + console.log("sessionStorage cleared.") + + // Attempt to delete specific database 'tesseract' and all other IndexedDB databases + await deleteIndexedDB('tesseract') + console.log("Database 'tesseract' cleared if it existed.") + + const dbNames = await indexedDB.databases() + for (let dbInfo of dbNames) { + if (dbInfo.name) { + const result = await deleteIndexedDB(dbInfo.name) + if (result === 'Blocked') { + console.warn(`Could not delete database '${dbInfo.name}' due to blocking issues.`) + } + } + } + console.log("All IndexedDB data cleared, where not blocked.") + + // Clear cookies + document.cookie.split(';').forEach(cookie => { + const cookieName = cookie.split('=')[0].trim() + document.cookie = cookieName + '=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/' + }) + console.log("Cookies cleared.") + + // Redirect to '/auth' with cache busting to prevent stale cache loading + window.location.href = '/auth?cacheBust=' + new Date().getTime() + } catch (error) { + console.error("Error clearing data:", error) + } +} + + $: auth = AuthStore.state $: saveSeedPhrase = $auth.saveSeedPhrase $: showSeed = seedPhrase ? SeedState.Hidden : SeedState.Missing @@ -571,6 +634,19 @@ +
+ + + +