Skip to content

Commit

Permalink
fix: thread abort signal through login functions (#1189)
Browse files Browse the repository at this point in the history
we rely on this in console to allow users to cancel login
  • Loading branch information
travis authored Nov 28, 2023
1 parent e8bffe2 commit 8e908a9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
6 changes: 4 additions & 2 deletions packages/w3up-client/src/account.js
Original file line number Diff line number Diff line change
Expand Up @@ -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<API.Result<Account, Error>>}
*/
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
Expand Down Expand Up @@ -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 }
Expand Down
6 changes: 4 additions & 2 deletions packages/w3up-client/src/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 8e908a9

Please sign in to comment.