blob: 589e5a58bde2b4e08e14448d5c6d4a9ef21ffabb (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
import { crdtSyncStateManager } from "../sync/crdt/sync-state";
import { syncQueue } from "../sync/queue";
import { db } from "./index";
/**
* Clears all locally persisted user-scoped data: the main IndexedDB tables,
* the sync queue state, and the CRDT sync state. Used at explicit logout to
* prevent the next user from seeing the previous user's offline data.
*
* Each step is isolated so that a partial failure (e.g. one tab still has the
* Dexie connection open) does not stop the rest from running.
*/
export async function clearAllLocalData(): Promise<void> {
const results = await Promise.allSettled([
syncQueue.reset(),
crdtSyncStateManager.clearAll(),
db.delete(),
]);
for (const result of results) {
if (result.status === "rejected") {
console.error("Failed to clear local data:", result.reason);
}
}
}
|