Soft logout keeps local data and re-logs in on the same device; MAS front hides register and reset
Soft (soft_logout === true) drops only the access token and records the device; sign-in is fixed to that user and sends device_id; same user and device keeps the stores, anything else wipes via the one wipeLocalData. Hard logout still wipes. When discovery advertises an msc2965 account or issuer, the register and forgot-password entries give way to a notice pointing at the account page. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
dc9a541820
commit
4fd83fb4c4
15 changed files with 541 additions and 77 deletions
|
|
@ -111,6 +111,45 @@ 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();
|
||||
|
|
@ -119,21 +158,11 @@ export const logoutClient = async (mx: MatrixClient) => {
|
|||
} catch {
|
||||
// ignore if failed to logout
|
||||
}
|
||||
await mx.clearStores();
|
||||
window.localStorage.clear();
|
||||
await wipeLocalData(mx);
|
||||
window.location.reload();
|
||||
};
|
||||
|
||||
export const clearLoginData = async () => {
|
||||
const dbs = await window.indexedDB.databases();
|
||||
|
||||
dbs.forEach((idbInfo) => {
|
||||
const { name } = idbInfo;
|
||||
if (name) {
|
||||
window.indexedDB.deleteDatabase(name);
|
||||
}
|
||||
});
|
||||
|
||||
window.localStorage.clear();
|
||||
await wipeLocalData();
|
||||
window.location.reload();
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in a new issue