forked from mystiq/hydrogen-web
Delete localstorage on logout
This commit is contained in:
parent
c898bcb46a
commit
bfd54f2764
2 changed files with 19 additions and 0 deletions
|
@ -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.
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue