-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add public route to reset local data
When the stack serves the login page, we take this opportunity to remove any remaining local data, i.e. indexedDB and localstorage data. See how it is done for the stack part: cozy/cozy-stack#4483
- Loading branch information
1 parent
607d336
commit be4523e
Showing
9 changed files
with
79 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import Minilog from 'cozy-minilog' | ||
|
||
import { LOCALSTORAGE_KEY_DELETING_DATA } from '@/search/consts' | ||
const log = Minilog('👷♂️ [Worker utils]') | ||
|
||
const deleteDatabases = async (): Promise<void> => { | ||
const databases = await window.indexedDB.databases() | ||
// Remove all indexedDB databases | ||
for (const db of databases) { | ||
if (db.name) { | ||
window.indexedDB.deleteDatabase(db.name) | ||
log.info('Deleted indexedDB database : ', db.name) | ||
} | ||
} | ||
} | ||
|
||
export const removeStaleLocalData = async (): Promise<void> => { | ||
// Check flag existence proving the reset process was incomplete | ||
const hasStaleData = localStorage.getItem(LOCALSTORAGE_KEY_DELETING_DATA) | ||
if (hasStaleData) { | ||
log.info('Found stale data: remove it') | ||
await deleteDatabases() | ||
localStorage.removeItem(LOCALSTORAGE_KEY_DELETING_DATA) | ||
} | ||
return | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<html> | ||
<head> | ||
<script src="reset/reset.js"> | ||
</script> | ||
</head> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* eslint-disable no-console */ | ||
|
||
function resetData() { | ||
// Remove localstorage | ||
window.localStorage.clear() | ||
console.log('Deleted localStorage') | ||
|
||
// Add this flag for future check | ||
window.localStorage.setItem('deletingLocalData', new Date().toISOString()) | ||
|
||
// Remove all indexedDB databases | ||
window.indexedDB.databases().then(function (databases) { | ||
databases.forEach(function (db) { | ||
window.indexedDB.deleteDatabase(db.name) | ||
console.log('Deleted indexedDB database : ', db.name) | ||
}) | ||
// Everything is done, remove the flag | ||
window.localStorage.removeItem('deletingLocalData') | ||
}) | ||
} | ||
|
||
resetData() |