From 42f1603d8191a9e6fc700a5e1bcd58b2a1b2e179 Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Thu, 30 Sep 2021 09:25:35 +0200 Subject: [PATCH] use correct prefix to remove local storage value --- src/matrix/storage/idb/stores/SessionStore.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/matrix/storage/idb/stores/SessionStore.ts b/src/matrix/storage/idb/stores/SessionStore.ts index 2158dc23..785835b8 100644 --- a/src/matrix/storage/idb/stores/SessionStore.ts +++ b/src/matrix/storage/idb/stores/SessionStore.ts @@ -33,6 +33,10 @@ export class SessionStore { this._localStorage = localStorage; } + private get _localStorageKeyPrefix(): string { + return `${this._sessionStore.databaseName}.session.`; + } + async get(key: string): Promise { const entry = await this._sessionStore.get(key); if (entry) { @@ -43,7 +47,7 @@ export class SessionStore { _writeKeyToLocalStorage(key: string, value: any) { // we backup to localStorage so when idb gets cleared for some reason, we don't lose our e2ee identity try { - const lsKey = `${this._sessionStore.databaseName}.session.${key}`; + const lsKey = this._localStorageKeyPrefix + key; const lsValue = stringify(value); this._localStorage.setItem(lsKey, lsValue); } catch (err) { @@ -62,8 +66,8 @@ export class SessionStore { async tryRestoreE2EEIdentityFromLocalStorage(log: LogItem): Promise { let success = false; - const lsPrefix = `${this._sessionStore.databaseName}.session.`; - const prefix = `${lsPrefix}${SESSION_E2EE_KEY_PREFIX}`; + const lsPrefix = this._localStorageKeyPrefix; + const prefix = lsPrefix + SESSION_E2EE_KEY_PREFIX; for(let i = 0; i < this._localStorage.length; i += 1) { const lsKey = this._localStorage.key(i)!; if (lsKey.startsWith(prefix)) { @@ -97,7 +101,7 @@ export class SessionStore { remove(key: string): void { if (key.startsWith(SESSION_E2EE_KEY_PREFIX)) { - this._localStorage.removeItem(this._sessionStore.databaseName + key); + this._localStorage.removeItem(this._localStorageKeyPrefix + key); } this._sessionStore.delete(key); }