Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(profile): delete account #826

Merged
merged 6 commits into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/lib/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,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",
Expand Down
61 changes: 61 additions & 0 deletions src/routes/settings/profile/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,54 @@
isValidUsernameToUpdate = false
}

// Function to delete an IndexedDB database
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.`);
};
});
}

// Function to clear all IndexedDB data, localStorage, sessionStorage, and cookies
async function clearAllData() {
// Clear all IndexedDB databases
const dbNames = await indexedDB.databases();
for (let dbInfo of dbNames) {
await deleteIndexedDB(dbInfo.name);
}
console.log("All IndexedDB data cleared.");

// Clear localStorage and sessionStorage
localStorage.clear();
sessionStorage.clear();
console.log("localStorage and sessionStorage cleared.");

// Clear cookies
document.cookie.split(';').forEach(function(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' and reload the page
window.location.href = '/auth'; // Redirect to '/auth'
location.reload(); // Reload the page
}


$: auth = AuthStore.state
$: saveSeedPhrase = $auth.saveSeedPhrase
$: showSeed = seedPhrase ? SeedState.Hidden : SeedState.Missing
Expand Down Expand Up @@ -571,6 +619,19 @@
</Button>
</SettingSection>
</div>
<div class="section">
<SettingSection hook="section-delete-account" name={$_("settings.profile.delete_title")} description={$_("settings.profile.delete_subtitle")}>
<Button
hook="button-delete-account"
appearance={Appearance.Alt}
text={$_("settings.profile.delete_title")}
on:click={_ => {
clearAllData()
}}>
<Icon icon={Shape.Lock} />
</Button>
</SettingSection>
</div>
</div>
</div>
</div>
Expand Down
Loading