From ccac96ae7e4a905e8d92dc70ca3f7463cacc5347 Mon Sep 17 00:00:00 2001 From: hjaber Date: Thu, 14 Nov 2024 13:54:28 -0800 Subject: [PATCH] Allow passing custom AbortController to register and authenticate functions without breaking existing behavior --- src/client.ts | 45 +++++++++++++++++++++++++++++++++------------ src/types.ts | 2 ++ 2 files changed, 35 insertions(+), 12 deletions(-) diff --git a/src/client.ts b/src/client.ts index d3d8f67..f756acb 100644 --- a/src/client.ts +++ b/src/client.ts @@ -1,4 +1,4 @@ -import { AuthenticateOptions, AuthenticationJSON, Base64URLString, CredentialDescriptor, ExtendedAuthenticatorTransport, PublicKeyCredentialHints, RegisterOptions, RegistrationJSON, User, WebAuthnCreateOptions, WebAuthnGetOptions } from './types.js' +import { AuthenticateOptions, AuthenticationJSON, Base64URLString, CredentialDescriptor, PublicKeyCredentialHints, RegisterOptions, RegistrationJSON, User, WebAuthnCreateOptions, WebAuthnGetOptions } from './types.js' import * as utils from './utils' /** @@ -53,6 +53,8 @@ let ongoingAuth: AbortController | null = null; * @param {'discouraged'|'preferred'|'required'} [discoverable] A "discoverable" credential can be selected using `authenticate(...)` without providing credential IDs. * Instead, a native pop-up will appear for user selection. * This may have an impact on the "passkeys" user experience and syncing behavior of the key. + * * @param {AbortSignal} [signal] An optional AbortSignal to allow aborting the registration process. + * If not provided, a global AbortController is used to abort any ongoing authentication. */ export async function register(options: RegisterOptions): Promise { @@ -97,14 +99,23 @@ export async function register(options: RegisterOptions): Promise { if (!utils.isBase64url(options.challenge)) @@ -169,16 +182,24 @@ export async function authenticate(options: AuthenticateOptions): Promise