From ba3de43608e1e6c8124ddbb7b261719a65bbf676 Mon Sep 17 00:00:00 2001 From: pavanjoshi914 Date: Thu, 5 Sep 2024 16:59:48 +0530 Subject: [PATCH] feat: add identifier in auth url persist identifier in account config --- .../background-script/connectors/alby.ts | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/extension/background-script/connectors/alby.ts b/src/extension/background-script/connectors/alby.ts index 23c8530467..fada7ec0a2 100644 --- a/src/extension/background-script/connectors/alby.ts +++ b/src/extension/background-script/connectors/alby.ts @@ -34,6 +34,7 @@ interface Config { password: string; url: string; oAuthToken: OAuthToken | undefined; + userIdentifer: string | undefined; } export default class Alby implements Connector { @@ -64,6 +65,25 @@ export default class Alby implements Connector { return this.config.oAuthToken; } + async persistUserIdentifier(userIdentifier: string): Promise { + if (!this.config.userIdentifer) { + if (this.account.id) { + const accounts = state.getState().accounts; + const password = (await state.getState().password()) as string; + + const configData = decryptData( + accounts[this.account.id].config, + password + ); + configData.userIdentifer = userIdentifier; + accounts[this.account.id].config = encryptData(configData, password); + state.setState({ accounts }); + // make sure we immediately persist the updated accounts + await state.getState().saveToStorage(); + } + } + } + unload() { return Promise.resolve(); } @@ -123,6 +143,9 @@ export default class Alby implements Connector { >; if (cacheValue) { + if (!this.config.userIdentifer) { + this.persistUserIdentifier(cacheValue.data.identifier); + } return cacheValue; } @@ -137,6 +160,9 @@ export default class Alby implements Connector { }; this._cache.set(cacheKey, returnValue); + if (!this.config.userIdentifer) { + this.persistUserIdentifier(info.identifier); + } return returnValue; } catch (error) { console.error(error); @@ -295,6 +321,9 @@ export default class Alby implements Connector { }); authUrl += "&webln=false"; // stop getalby.com login modal launching lnurl auth + if (this.config.userIdentifer) { + authUrl += `&identifier=${this.config.userIdentifer}`; + } const oAuthTab = await browser.tabs.create({ url: authUrl });