Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add identifier in auth url #3239

Merged
merged 2 commits into from
Sep 8, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions src/extension/background-script/connectors/alby.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ interface Config {
password: string;
url: string;
oAuthToken: OAuthToken | undefined;
userIdentifer: string | undefined;
}

export default class Alby implements Connector {
Expand Down Expand Up @@ -64,6 +65,25 @@ export default class Alby implements Connector {
return this.config.oAuthToken;
}

async persistUserIdentifier(userIdentifier: string): Promise<void> {
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();
}
pavanjoshi914 marked this conversation as resolved.
Show resolved Hide resolved
}
}

unload() {
return Promise.resolve();
}
Expand Down Expand Up @@ -123,6 +143,9 @@ export default class Alby implements Connector {
>;

if (cacheValue) {
if (!this.config.userIdentifer) {
this.persistUserIdentifier(cacheValue.data.identifier);
}
return cacheValue;
}

Expand All @@ -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);
Expand Down Expand Up @@ -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 });

Expand Down
Loading