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
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:
parent
3a5258c3ef
commit
31d58075db
10 changed files with 271 additions and 85 deletions
|
|
@ -7,6 +7,7 @@ import {
|
|||
SyncState,
|
||||
} from 'matrix-js-sdk';
|
||||
|
||||
import { wipeLocalData } from './wipeLocalData';
|
||||
import { cryptoCallbacks } from './secretStorageKeys';
|
||||
import { clearNavToActivePathStore } from '../app/state/navToActivePath';
|
||||
import { pushSessionToSW } from '../sw-session';
|
||||
|
|
@ -111,45 +112,6 @@ export const clearCacheAndReload = async (mx: MatrixClient) => {
|
|||
window.location.reload();
|
||||
};
|
||||
|
||||
// The rust crypto databases the SDK names, for browsers without indexedDB.databases().
|
||||
const KNOWN_DATABASES = [
|
||||
'web-sync-store',
|
||||
'crypto-store',
|
||||
'matrix-js-sdk::matrix-sdk-crypto',
|
||||
'matrix-js-sdk::matrix-sdk-crypto-meta',
|
||||
];
|
||||
|
||||
const deleteDatabase = (name: string) =>
|
||||
new Promise<void>((resolve) => {
|
||||
const req = window.indexedDB.deleteDatabase(name);
|
||||
req.onsuccess = () => resolve();
|
||||
req.onerror = () => resolve();
|
||||
req.onblocked = () => 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. Callers reload afterwards.
|
||||
*/
|
||||
export const wipeLocalData = async (mx?: MatrixClient) => {
|
||||
try {
|
||||
await mx?.clearStores();
|
||||
} catch {
|
||||
// the databases go below regardless
|
||||
}
|
||||
let names: string[];
|
||||
try {
|
||||
names = (await window.indexedDB.databases())
|
||||
.map((db) => db.name)
|
||||
.filter((name): name is string => !!name);
|
||||
} catch {
|
||||
names = KNOWN_DATABASES;
|
||||
}
|
||||
await Promise.all(names.map(deleteDatabase));
|
||||
window.localStorage.clear();
|
||||
};
|
||||
|
||||
export const logoutClient = async (mx: MatrixClient) => {
|
||||
pushSessionToSW();
|
||||
mx.stopClient();
|
||||
|
|
|
|||
Loading…
Reference in a new issue