diff --git a/src/matrix/Client.js b/src/matrix/Client.js index 44643cc1..438bf3ab 100644 --- a/src/matrix/Client.js +++ b/src/matrix/Client.js @@ -451,6 +451,12 @@ export class Client { async deleteSession(log) { if (this._sessionId) { + await log.wrap("sessionStore", async () => { + const storage = this._storage ?? await this._platform.storageFactory.create(this._sessionId, log); + const txn = await storage.readWriteTxn([storage.storeNames.session]); + txn.session.delete(); + storage.close(); + }); // need to dispose first, so the storage is closed, // and also first sync finishing won't call Session.start anymore, // which assumes that the storage works. diff --git a/src/matrix/storage/idb/stores/SessionStore.ts b/src/matrix/storage/idb/stores/SessionStore.ts index 7faedc41..a7aaf594 100644 --- a/src/matrix/storage/idb/stores/SessionStore.ts +++ b/src/matrix/storage/idb/stores/SessionStore.ts @@ -105,4 +105,17 @@ export class SessionStore { } this._sessionStore.delete(key); } + + delete(): void { + const keys: string[] = []; + for (let i = 0; i < localStorage.length; i++) { + const key = this._localStorage.key(i); + if (key?.startsWith(this._localStorageKeyPrefix)) { + keys.push(key); + } + } + for (const key of keys) { + this._localStorage.removeItem(key); + } + } }