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 all commits
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 @@ -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",
Expand Down
76 changes: 76 additions & 0 deletions src/routes/settings/profile/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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')
stavares843 marked this conversation as resolved.
Show resolved Hide resolved
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
Expand Down Expand Up @@ -571,6 +634,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