♻️ Drop legacy browser storage on sign-in
Browsers of users of the Dexie based version still hold its token in the auth_token key of localStorage and its database named wotra, next to the per user databases of this version. resolveGate() now removes both whenever it lets the user into the app, the first open included. The removal resolves on success, error and block, like wipeLocal, and never throws, so a browser that denies storage cannot keep the user out.
This commit is contained in:
+33
-1
@@ -1,7 +1,7 @@
|
||||
import { Collection } from '@signaldb/core';
|
||||
import { tick } from 'svelte';
|
||||
import { afterAll, beforeEach, describe, expect, it, vi } from 'vitest';
|
||||
import { all, closeDb, get, openDb, pendingCount, remove, save, status, syncNow, toRecord, update } from './db.svelte';
|
||||
import { all, closeDb, get, openDb, pendingCount, remove, removeLegacyStorage, save, status, syncNow, toRecord, update } from './db.svelte';
|
||||
import { watch } from './testing.svelte';
|
||||
|
||||
const mocks = vi.hoisted(() => {
|
||||
@@ -162,6 +162,38 @@ describe('read scopes', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('legacy storage', () => {
|
||||
const open = (name: string) =>
|
||||
new Promise<void>((resolve, reject) => {
|
||||
const req = indexedDB.open(name);
|
||||
req.onsuccess = () => {
|
||||
req.result.close();
|
||||
resolve();
|
||||
};
|
||||
req.onerror = () => reject(req.error);
|
||||
});
|
||||
const names = async () => (await indexedDB.databases()).map((d) => d.name);
|
||||
|
||||
it('removeLegacyStorage drops the token and the Dexie database', async () => {
|
||||
localStorage.setItem('auth_token', 'secret');
|
||||
await open('wotra');
|
||||
expect(await names()).toContain('wotra');
|
||||
await removeLegacyStorage();
|
||||
expect(localStorage.getItem('auth_token')).toBeNull();
|
||||
expect(await names()).not.toContain('wotra');
|
||||
expect(await names()).toContain(`wotra-user-${n}`);
|
||||
});
|
||||
|
||||
it('removeLegacyStorage never throws', async () => {
|
||||
vi.stubGlobal('indexedDB', undefined);
|
||||
try {
|
||||
await expect(removeLegacyStorage()).resolves.toBeUndefined();
|
||||
} finally {
|
||||
vi.unstubAllGlobals();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe('sync boundary', () => {
|
||||
it('toRecord turns end_time 0 into null and coerces the metadata', () => {
|
||||
const doc = toRecord('entries', {
|
||||
|
||||
Reference in New Issue
Block a user