Second Soul pass: soft event without a session wipes, wipe never rejects, rendered MAS tests
Some checks failed
Build pull request / Build pull request (pull_request) Has been cancelled

wipeLocalData moves to its own module with injectable ports: per-database failures are contained and localStorage clears in a finally. A soft logout with no session to remember is treated as hard. Login/PasswordLoginForm/ResetPassword MAS behavior is now tested by rendering. Login and register completion settle once per response.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Void 2026-11-13 18:56:08 +00:00
commit 31d58075db
10 changed files with 271 additions and 85 deletions

View file

@ -0,0 +1,58 @@
import type { MatrixClient } from 'matrix-js-sdk';
// The rust crypto databases the SDK names, for browsers without indexedDB.databases().
export const KNOWN_DATABASES = [
'web-sync-store',
'crypto-store',
'matrix-js-sdk::matrix-sdk-crypto',
'matrix-js-sdk::matrix-sdk-crypto-meta',
];
export type WipePorts = {
indexedDB: Pick<IDBFactory, 'deleteDatabase'> & {
databases?: () => Promise<{ name?: string }[]>;
};
storage: Pick<Storage, 'clear'>;
};
const deleteDatabase = (idb: WipePorts['indexedDB'], name: string) =>
new Promise<void>((resolve) => {
try {
const req = idb.deleteDatabase(name);
req.onsuccess = () => resolve();
req.onerror = () => resolve();
req.onblocked = () => resolve();
} catch {
// one database failing must not stop the rest
resolve();
}
});
/**
* The one wipe of everything this browser holds for the account: client stores, every IndexedDB
* database, localStorage. Hard logout, a soft logout answered by another user or device, and
* "sign in as someone else" all end here. It never rejects, and localStorage (the access token
* with it) is cleared whatever the databases do. Callers reload afterwards.
*/
export const wipeLocalData = async (
mx?: MatrixClient,
ports: WipePorts = { indexedDB: window.indexedDB, storage: window.localStorage }
): Promise<void> => {
try {
try {
await mx?.clearStores();
} catch {
// the databases go below regardless
}
let names = KNOWN_DATABASES;
try {
const listed = await ports.indexedDB.databases?.();
if (listed) names = listed.map((db) => db.name).filter((n): n is string => !!n);
} catch {
// keep the known names
}
await Promise.all(names.map((name) => deleteDatabase(ports.indexedDB, name)));
} finally {
ports.storage.clear();
}
};