From c3003abd193199909ff0d652bb04bf697bc50349 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 | 47 +++++++++++++++++++++++++++++++++++------------ src/types.ts | 2 ++ 2 files changed, 37 insertions(+), 12 deletions(-) diff --git a/src/client.ts b/src/client.ts index d3d8f67..113e627 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,9 @@ 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, an `AbortController` (stored in `ongoingAuth`) is used to cancel any previous ongoing authentication or registration + * if another `authenticate()` or `register()` call is made. */ export async function register(options: RegisterOptions): Promise { @@ -97,14 +100,23 @@ export async function register(options: RegisterOptions): Promise { if (!utils.isBase64url(options.challenge)) @@ -169,16 +184,24 @@ export async function authenticate(options: AuthenticateOptions): Promise