diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-05-02 11:31:42 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-05-02 11:31:42 +0900 |
| commit | 13a3d16ffc88845d7bc65fb0778da9aaff53b653 (patch) | |
| tree | f05ab5d06b3a6608951f8ba47ff57e7f4443d371 /src/client/db/clear.ts | |
| parent | d9b78a9fa440d84c6cd0c1f2a6ebb43df895ccdf (diff) | |
| download | kioku-13a3d16ffc88845d7bc65fb0778da9aaff53b653.tar.gz kioku-13a3d16ffc88845d7bc65fb0778da9aaff53b653.tar.zst kioku-13a3d16ffc88845d7bc65fb0778da9aaff53b653.zip | |
feat(auth): clear local IndexedDB and sync state on explicit logout
Wipe Dexie databases (main + CRDT sync state) and reset the sync queue
when the user explicitly logs out so the next account on the same device
starts from a clean local store. Session expiry deliberately keeps local
data intact so a returning user finds their offline work waiting.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Diffstat (limited to 'src/client/db/clear.ts')
| -rw-r--r-- | src/client/db/clear.ts | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/client/db/clear.ts b/src/client/db/clear.ts new file mode 100644 index 0000000..589e5a5 --- /dev/null +++ b/src/client/db/clear.ts @@ -0,0 +1,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); + } + } +} |
