From 8e908a9fbacaedb40fdaf214f862720fb8454fca Mon Sep 17 00:00:00 2001 From: Travis Vachon Date: Mon, 27 Nov 2023 16:25:14 -0800 Subject: [PATCH] fix: thread abort signal through login functions (#1189) we rely on this in console to allow users to cancel login --- packages/w3up-client/src/account.js | 6 ++++-- packages/w3up-client/src/client.js | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/packages/w3up-client/src/account.js b/packages/w3up-client/src/account.js index 1cccf775e..60689f352 100644 --- a/packages/w3up-client/src/account.js +++ b/packages/w3up-client/src/account.js @@ -77,9 +77,11 @@ export const list = ({ agent }, { account } = {}) => { * * @param {{agent: API.Agent}} client * @param {EmailAddress} email + * @param {object} [options] + * @param {AbortSignal} [options.signal] * @returns {Promise>} */ -export const login = async ({ agent }, email) => { +export const login = async ({ agent }, email, options = {}) => { const account = fromEmail(email) // If we already have a session for this account we @@ -110,7 +112,7 @@ export const login = async ({ agent }, email) => { if (error) { return { error } } else { - const { ok, error } = await access.claim() + const { ok, error } = await access.claim({ signal: options.signal }) /* c8 ignore next 2 - don't know how to test this */ if (error) { return { error } diff --git a/packages/w3up-client/src/client.js b/packages/w3up-client/src/client.js index f4ca363e3..c77d6d61d 100644 --- a/packages/w3up-client/src/client.js +++ b/packages/w3up-client/src/client.js @@ -76,9 +76,11 @@ export class Client extends Base { /** * @param {Account.EmailAddress} email + * @param {object} [options] + * @param {AbortSignal} [options.signal] */ - async login(email) { - const account = Result.unwrap(await Account.login(this, email)) + async login(email, options = {}) { + const account = Result.unwrap(await Account.login(this, email, options)) Result.unwrap(await account.save()) return account }