@absolutejs/auth 0.36.0 → 0.38.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,8 +1,563 @@
1
1
  // @bun
2
+ var __defProp = Object.defineProperty;
3
+ var __returnValue = (v) => v;
4
+ function __exportSetter(name, newValue) {
5
+ this[name] = __returnValue.bind(null, newValue);
6
+ }
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, {
10
+ get: all[name],
11
+ enumerable: true,
12
+ configurable: true,
13
+ set: __exportSetter.bind(all, name)
14
+ });
15
+ };
16
+ var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
2
17
  var __require = import.meta.require;
3
18
 
19
+ // node_modules/@simplewebauthn/browser/esm/helpers/bufferToBase64URLString.js
20
+ function bufferToBase64URLString(buffer) {
21
+ const bytes = new Uint8Array(buffer);
22
+ let str = "";
23
+ for (const charCode of bytes) {
24
+ str += String.fromCharCode(charCode);
25
+ }
26
+ const base64String = btoa(str);
27
+ return base64String.replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, "");
28
+ }
29
+
30
+ // node_modules/@simplewebauthn/browser/esm/helpers/base64URLStringToBuffer.js
31
+ function base64URLStringToBuffer(base64URLString) {
32
+ const base64 = base64URLString.replace(/-/g, "+").replace(/_/g, "/");
33
+ const padLength = (4 - base64.length % 4) % 4;
34
+ const padded = base64.padEnd(base64.length + padLength, "=");
35
+ const binary = atob(padded);
36
+ const buffer = new ArrayBuffer(binary.length);
37
+ const bytes = new Uint8Array(buffer);
38
+ for (let i = 0;i < binary.length; i++) {
39
+ bytes[i] = binary.charCodeAt(i);
40
+ }
41
+ return buffer;
42
+ }
43
+
44
+ // node_modules/@simplewebauthn/browser/esm/helpers/browserSupportsWebAuthn.js
45
+ function browserSupportsWebAuthn() {
46
+ return _browserSupportsWebAuthnInternals.stubThis(globalThis?.PublicKeyCredential !== undefined && typeof globalThis.PublicKeyCredential === "function");
47
+ }
48
+ var _browserSupportsWebAuthnInternals;
49
+ var init_browserSupportsWebAuthn = __esm(() => {
50
+ _browserSupportsWebAuthnInternals = {
51
+ stubThis: (value) => value
52
+ };
53
+ });
54
+
55
+ // node_modules/@simplewebauthn/browser/esm/helpers/toPublicKeyCredentialDescriptor.js
56
+ function toPublicKeyCredentialDescriptor(descriptor) {
57
+ const { id } = descriptor;
58
+ return {
59
+ ...descriptor,
60
+ id: base64URLStringToBuffer(id),
61
+ transports: descriptor.transports
62
+ };
63
+ }
64
+ var init_toPublicKeyCredentialDescriptor = () => {};
65
+
66
+ // node_modules/@simplewebauthn/browser/esm/helpers/isValidDomain.js
67
+ function isValidDomain(hostname) {
68
+ return hostname === "localhost" || /^((xn--[a-z0-9-]+|[a-z0-9]+(-[a-z0-9]+)*)\.)+([a-z]{2,}|xn--[a-z0-9-]+)$/i.test(hostname);
69
+ }
70
+
71
+ // node_modules/@simplewebauthn/browser/esm/helpers/webAuthnError.js
72
+ var WebAuthnError;
73
+ var init_webAuthnError = __esm(() => {
74
+ WebAuthnError = class WebAuthnError extends Error {
75
+ constructor({ message, code, cause, name }) {
76
+ super(message, { cause });
77
+ Object.defineProperty(this, "code", {
78
+ enumerable: true,
79
+ configurable: true,
80
+ writable: true,
81
+ value: undefined
82
+ });
83
+ this.name = name ?? cause.name;
84
+ this.code = code;
85
+ }
86
+ };
87
+ });
88
+
89
+ // node_modules/@simplewebauthn/browser/esm/helpers/identifyRegistrationError.js
90
+ function identifyRegistrationError({ error, options }) {
91
+ const { publicKey } = options;
92
+ if (!publicKey) {
93
+ throw Error("options was missing required publicKey property");
94
+ }
95
+ if (error.name === "AbortError") {
96
+ if (options.signal instanceof AbortSignal) {
97
+ return new WebAuthnError({
98
+ message: "Registration ceremony was sent an abort signal",
99
+ code: "ERROR_CEREMONY_ABORTED",
100
+ cause: error
101
+ });
102
+ }
103
+ } else if (error.name === "ConstraintError") {
104
+ if (publicKey.authenticatorSelection?.requireResidentKey === true) {
105
+ return new WebAuthnError({
106
+ message: "Discoverable credentials were required but no available authenticator supported it",
107
+ code: "ERROR_AUTHENTICATOR_MISSING_DISCOVERABLE_CREDENTIAL_SUPPORT",
108
+ cause: error
109
+ });
110
+ } else if (options.mediation === "conditional" && publicKey.authenticatorSelection?.userVerification === "required") {
111
+ return new WebAuthnError({
112
+ message: "User verification was required during automatic registration but it could not be performed",
113
+ code: "ERROR_AUTO_REGISTER_USER_VERIFICATION_FAILURE",
114
+ cause: error
115
+ });
116
+ } else if (publicKey.authenticatorSelection?.userVerification === "required") {
117
+ return new WebAuthnError({
118
+ message: "User verification was required but no available authenticator supported it",
119
+ code: "ERROR_AUTHENTICATOR_MISSING_USER_VERIFICATION_SUPPORT",
120
+ cause: error
121
+ });
122
+ }
123
+ } else if (error.name === "InvalidStateError") {
124
+ return new WebAuthnError({
125
+ message: "The authenticator was previously registered",
126
+ code: "ERROR_AUTHENTICATOR_PREVIOUSLY_REGISTERED",
127
+ cause: error
128
+ });
129
+ } else if (error.name === "NotAllowedError") {
130
+ return new WebAuthnError({
131
+ message: error.message,
132
+ code: "ERROR_PASSTHROUGH_SEE_CAUSE_PROPERTY",
133
+ cause: error
134
+ });
135
+ } else if (error.name === "NotSupportedError") {
136
+ const validPubKeyCredParams = publicKey.pubKeyCredParams.filter((param) => param.type === "public-key");
137
+ if (validPubKeyCredParams.length === 0) {
138
+ return new WebAuthnError({
139
+ message: 'No entry in pubKeyCredParams was of type "public-key"',
140
+ code: "ERROR_MALFORMED_PUBKEYCREDPARAMS",
141
+ cause: error
142
+ });
143
+ }
144
+ return new WebAuthnError({
145
+ message: "No available authenticator supported any of the specified pubKeyCredParams algorithms",
146
+ code: "ERROR_AUTHENTICATOR_NO_SUPPORTED_PUBKEYCREDPARAMS_ALG",
147
+ cause: error
148
+ });
149
+ } else if (error.name === "SecurityError") {
150
+ const effectiveDomain = globalThis.location.hostname;
151
+ if (!isValidDomain(effectiveDomain)) {
152
+ return new WebAuthnError({
153
+ message: `${globalThis.location.hostname} is an invalid domain`,
154
+ code: "ERROR_INVALID_DOMAIN",
155
+ cause: error
156
+ });
157
+ } else if (publicKey.rp.id !== effectiveDomain) {
158
+ return new WebAuthnError({
159
+ message: `The RP ID "${publicKey.rp.id}" is invalid for this domain`,
160
+ code: "ERROR_INVALID_RP_ID",
161
+ cause: error
162
+ });
163
+ }
164
+ } else if (error.name === "TypeError") {
165
+ if (publicKey.user.id.byteLength < 1 || publicKey.user.id.byteLength > 64) {
166
+ return new WebAuthnError({
167
+ message: "User ID was not between 1 and 64 characters",
168
+ code: "ERROR_INVALID_USER_ID_LENGTH",
169
+ cause: error
170
+ });
171
+ }
172
+ } else if (error.name === "UnknownError") {
173
+ return new WebAuthnError({
174
+ message: "The authenticator was unable to process the specified options, or could not create a new credential",
175
+ code: "ERROR_AUTHENTICATOR_GENERAL_ERROR",
176
+ cause: error
177
+ });
178
+ }
179
+ return error;
180
+ }
181
+ var init_identifyRegistrationError = __esm(() => {
182
+ init_webAuthnError();
183
+ });
184
+
185
+ // node_modules/@simplewebauthn/browser/esm/helpers/webAuthnAbortService.js
186
+ class BaseWebAuthnAbortService {
187
+ constructor() {
188
+ Object.defineProperty(this, "controller", {
189
+ enumerable: true,
190
+ configurable: true,
191
+ writable: true,
192
+ value: undefined
193
+ });
194
+ }
195
+ createNewAbortSignal() {
196
+ if (this.controller) {
197
+ const abortError = new Error("Cancelling existing WebAuthn API call for new one");
198
+ abortError.name = "AbortError";
199
+ this.controller.abort(abortError);
200
+ }
201
+ const newController = new AbortController;
202
+ this.controller = newController;
203
+ return newController.signal;
204
+ }
205
+ cancelCeremony() {
206
+ if (this.controller) {
207
+ const abortError = new Error("Manually cancelling existing WebAuthn API call");
208
+ abortError.name = "AbortError";
209
+ this.controller.abort(abortError);
210
+ this.controller = undefined;
211
+ }
212
+ }
213
+ }
214
+ var WebAuthnAbortService;
215
+ var init_webAuthnAbortService = __esm(() => {
216
+ WebAuthnAbortService = new BaseWebAuthnAbortService;
217
+ });
218
+
219
+ // node_modules/@simplewebauthn/browser/esm/helpers/toAuthenticatorAttachment.js
220
+ function toAuthenticatorAttachment(attachment) {
221
+ if (!attachment) {
222
+ return;
223
+ }
224
+ if (attachments.indexOf(attachment) < 0) {
225
+ return;
226
+ }
227
+ return attachment;
228
+ }
229
+ var attachments;
230
+ var init_toAuthenticatorAttachment = __esm(() => {
231
+ attachments = ["cross-platform", "platform"];
232
+ });
233
+
234
+ // node_modules/@simplewebauthn/browser/esm/methods/startRegistration.js
235
+ async function startRegistration(options) {
236
+ if (!options.optionsJSON && options.challenge) {
237
+ console.warn("startRegistration() was not called correctly. It will try to continue with the provided options, but this call should be refactored to use the expected call structure instead. See https://simplewebauthn.dev/docs/packages/browser#typeerror-cannot-read-properties-of-undefined-reading-challenge for more information.");
238
+ options = { optionsJSON: options };
239
+ }
240
+ const { optionsJSON, useAutoRegister = false } = options;
241
+ if (!browserSupportsWebAuthn()) {
242
+ throw new Error("WebAuthn is not supported in this browser");
243
+ }
244
+ const publicKey = {
245
+ ...optionsJSON,
246
+ challenge: base64URLStringToBuffer(optionsJSON.challenge),
247
+ user: {
248
+ ...optionsJSON.user,
249
+ id: base64URLStringToBuffer(optionsJSON.user.id)
250
+ },
251
+ excludeCredentials: optionsJSON.excludeCredentials?.map(toPublicKeyCredentialDescriptor)
252
+ };
253
+ const createOptions = {};
254
+ if (useAutoRegister) {
255
+ createOptions.mediation = "conditional";
256
+ }
257
+ createOptions.publicKey = publicKey;
258
+ createOptions.signal = WebAuthnAbortService.createNewAbortSignal();
259
+ let credential;
260
+ try {
261
+ credential = await navigator.credentials.create(createOptions);
262
+ } catch (err) {
263
+ throw identifyRegistrationError({ error: err, options: createOptions });
264
+ }
265
+ if (!credential) {
266
+ throw new Error("Registration was not completed");
267
+ }
268
+ const { id, rawId, response, type } = credential;
269
+ let transports = undefined;
270
+ if (typeof response.getTransports === "function") {
271
+ transports = response.getTransports();
272
+ }
273
+ let responsePublicKeyAlgorithm = undefined;
274
+ if (typeof response.getPublicKeyAlgorithm === "function") {
275
+ try {
276
+ responsePublicKeyAlgorithm = response.getPublicKeyAlgorithm();
277
+ } catch (error) {
278
+ warnOnBrokenImplementation("getPublicKeyAlgorithm()", error);
279
+ }
280
+ }
281
+ let responsePublicKey = undefined;
282
+ if (typeof response.getPublicKey === "function") {
283
+ try {
284
+ const _publicKey = response.getPublicKey();
285
+ if (_publicKey !== null) {
286
+ responsePublicKey = bufferToBase64URLString(_publicKey);
287
+ }
288
+ } catch (error) {
289
+ warnOnBrokenImplementation("getPublicKey()", error);
290
+ }
291
+ }
292
+ let responseAuthenticatorData;
293
+ if (typeof response.getAuthenticatorData === "function") {
294
+ try {
295
+ responseAuthenticatorData = bufferToBase64URLString(response.getAuthenticatorData());
296
+ } catch (error) {
297
+ warnOnBrokenImplementation("getAuthenticatorData()", error);
298
+ }
299
+ }
300
+ return {
301
+ id,
302
+ rawId: bufferToBase64URLString(rawId),
303
+ response: {
304
+ attestationObject: bufferToBase64URLString(response.attestationObject),
305
+ clientDataJSON: bufferToBase64URLString(response.clientDataJSON),
306
+ transports,
307
+ publicKeyAlgorithm: responsePublicKeyAlgorithm,
308
+ publicKey: responsePublicKey,
309
+ authenticatorData: responseAuthenticatorData
310
+ },
311
+ type,
312
+ clientExtensionResults: credential.getClientExtensionResults(),
313
+ authenticatorAttachment: toAuthenticatorAttachment(credential.authenticatorAttachment)
314
+ };
315
+ }
316
+ function warnOnBrokenImplementation(methodName, cause) {
317
+ console.warn(`The browser extension that intercepted this WebAuthn API call incorrectly implemented ${methodName}. You should report this error to them.
318
+ `, cause);
319
+ }
320
+ var init_startRegistration = __esm(() => {
321
+ init_browserSupportsWebAuthn();
322
+ init_toPublicKeyCredentialDescriptor();
323
+ init_identifyRegistrationError();
324
+ init_webAuthnAbortService();
325
+ init_toAuthenticatorAttachment();
326
+ });
327
+
328
+ // node_modules/@simplewebauthn/browser/esm/helpers/browserSupportsWebAuthnAutofill.js
329
+ function browserSupportsWebAuthnAutofill() {
330
+ if (!browserSupportsWebAuthn()) {
331
+ return _browserSupportsWebAuthnAutofillInternals.stubThis(new Promise((resolve) => resolve(false)));
332
+ }
333
+ const globalPublicKeyCredential = globalThis.PublicKeyCredential;
334
+ if (globalPublicKeyCredential?.isConditionalMediationAvailable === undefined) {
335
+ return _browserSupportsWebAuthnAutofillInternals.stubThis(new Promise((resolve) => resolve(false)));
336
+ }
337
+ return _browserSupportsWebAuthnAutofillInternals.stubThis(globalPublicKeyCredential.isConditionalMediationAvailable());
338
+ }
339
+ var _browserSupportsWebAuthnAutofillInternals;
340
+ var init_browserSupportsWebAuthnAutofill = __esm(() => {
341
+ init_browserSupportsWebAuthn();
342
+ _browserSupportsWebAuthnAutofillInternals = {
343
+ stubThis: (value) => value
344
+ };
345
+ });
346
+
347
+ // node_modules/@simplewebauthn/browser/esm/helpers/identifyAuthenticationError.js
348
+ function identifyAuthenticationError({ error, options }) {
349
+ const { publicKey } = options;
350
+ if (!publicKey) {
351
+ throw Error("options was missing required publicKey property");
352
+ }
353
+ if (error.name === "AbortError") {
354
+ if (options.signal instanceof AbortSignal) {
355
+ return new WebAuthnError({
356
+ message: "Authentication ceremony was sent an abort signal",
357
+ code: "ERROR_CEREMONY_ABORTED",
358
+ cause: error
359
+ });
360
+ }
361
+ } else if (error.name === "NotAllowedError") {
362
+ return new WebAuthnError({
363
+ message: error.message,
364
+ code: "ERROR_PASSTHROUGH_SEE_CAUSE_PROPERTY",
365
+ cause: error
366
+ });
367
+ } else if (error.name === "SecurityError") {
368
+ const effectiveDomain = globalThis.location.hostname;
369
+ if (!isValidDomain(effectiveDomain)) {
370
+ return new WebAuthnError({
371
+ message: `${globalThis.location.hostname} is an invalid domain`,
372
+ code: "ERROR_INVALID_DOMAIN",
373
+ cause: error
374
+ });
375
+ } else if (publicKey.rpId !== effectiveDomain) {
376
+ return new WebAuthnError({
377
+ message: `The RP ID "${publicKey.rpId}" is invalid for this domain`,
378
+ code: "ERROR_INVALID_RP_ID",
379
+ cause: error
380
+ });
381
+ }
382
+ } else if (error.name === "UnknownError") {
383
+ return new WebAuthnError({
384
+ message: "The authenticator was unable to process the specified options, or could not create a new assertion signature",
385
+ code: "ERROR_AUTHENTICATOR_GENERAL_ERROR",
386
+ cause: error
387
+ });
388
+ }
389
+ return error;
390
+ }
391
+ var init_identifyAuthenticationError = __esm(() => {
392
+ init_webAuthnError();
393
+ });
394
+
395
+ // node_modules/@simplewebauthn/browser/esm/methods/startAuthentication.js
396
+ async function startAuthentication(options) {
397
+ if (!options.optionsJSON && options.challenge) {
398
+ console.warn("startAuthentication() was not called correctly. It will try to continue with the provided options, but this call should be refactored to use the expected call structure instead. See https://simplewebauthn.dev/docs/packages/browser#typeerror-cannot-read-properties-of-undefined-reading-challenge for more information.");
399
+ options = { optionsJSON: options };
400
+ }
401
+ const { optionsJSON, useBrowserAutofill = false, verifyBrowserAutofillInput = true } = options;
402
+ if (!browserSupportsWebAuthn()) {
403
+ throw new Error("WebAuthn is not supported in this browser");
404
+ }
405
+ let allowCredentials;
406
+ if (optionsJSON.allowCredentials?.length !== 0) {
407
+ allowCredentials = optionsJSON.allowCredentials?.map(toPublicKeyCredentialDescriptor);
408
+ }
409
+ const publicKey = {
410
+ ...optionsJSON,
411
+ challenge: base64URLStringToBuffer(optionsJSON.challenge),
412
+ allowCredentials
413
+ };
414
+ const getOptions = {};
415
+ if (useBrowserAutofill) {
416
+ if (!await browserSupportsWebAuthnAutofill()) {
417
+ throw Error("Browser does not support WebAuthn autofill");
418
+ }
419
+ const eligibleInputs = document.querySelectorAll("input[autocomplete$='webauthn']");
420
+ if (eligibleInputs.length < 1 && verifyBrowserAutofillInput) {
421
+ throw Error('No <input> with "webauthn" as the only or last value in its `autocomplete` attribute was detected');
422
+ }
423
+ getOptions.mediation = "conditional";
424
+ publicKey.allowCredentials = [];
425
+ }
426
+ getOptions.publicKey = publicKey;
427
+ getOptions.signal = WebAuthnAbortService.createNewAbortSignal();
428
+ let credential;
429
+ try {
430
+ credential = await navigator.credentials.get(getOptions);
431
+ } catch (err) {
432
+ throw identifyAuthenticationError({ error: err, options: getOptions });
433
+ }
434
+ if (!credential) {
435
+ throw new Error("Authentication was not completed");
436
+ }
437
+ const { id, rawId, response, type } = credential;
438
+ let userHandle = undefined;
439
+ if (response.userHandle) {
440
+ userHandle = bufferToBase64URLString(response.userHandle);
441
+ }
442
+ return {
443
+ id,
444
+ rawId: bufferToBase64URLString(rawId),
445
+ response: {
446
+ authenticatorData: bufferToBase64URLString(response.authenticatorData),
447
+ clientDataJSON: bufferToBase64URLString(response.clientDataJSON),
448
+ signature: bufferToBase64URLString(response.signature),
449
+ userHandle
450
+ },
451
+ type,
452
+ clientExtensionResults: credential.getClientExtensionResults(),
453
+ authenticatorAttachment: toAuthenticatorAttachment(credential.authenticatorAttachment)
454
+ };
455
+ }
456
+ var init_startAuthentication = __esm(() => {
457
+ init_browserSupportsWebAuthn();
458
+ init_browserSupportsWebAuthnAutofill();
459
+ init_toPublicKeyCredentialDescriptor();
460
+ init_identifyAuthenticationError();
461
+ init_webAuthnAbortService();
462
+ init_toAuthenticatorAttachment();
463
+ });
464
+
465
+ // node_modules/@simplewebauthn/browser/esm/helpers/platformAuthenticatorIsAvailable.js
466
+ function platformAuthenticatorIsAvailable() {
467
+ if (!browserSupportsWebAuthn()) {
468
+ return new Promise((resolve) => resolve(false));
469
+ }
470
+ return PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable();
471
+ }
472
+ var init_platformAuthenticatorIsAvailable = __esm(() => {
473
+ init_browserSupportsWebAuthn();
474
+ });
475
+
476
+ // node_modules/@simplewebauthn/browser/esm/types/index.js
477
+ var init_types = () => {};
478
+
479
+ // node_modules/@simplewebauthn/browser/esm/index.js
480
+ var exports_esm = {};
481
+ __export(exports_esm, {
482
+ startRegistration: () => startRegistration,
483
+ startAuthentication: () => startAuthentication,
484
+ platformAuthenticatorIsAvailable: () => platformAuthenticatorIsAvailable,
485
+ bufferToBase64URLString: () => bufferToBase64URLString,
486
+ browserSupportsWebAuthnAutofill: () => browserSupportsWebAuthnAutofill,
487
+ browserSupportsWebAuthn: () => browserSupportsWebAuthn,
488
+ base64URLStringToBuffer: () => base64URLStringToBuffer,
489
+ _browserSupportsWebAuthnInternals: () => _browserSupportsWebAuthnInternals,
490
+ _browserSupportsWebAuthnAutofillInternals: () => _browserSupportsWebAuthnAutofillInternals,
491
+ WebAuthnError: () => WebAuthnError,
492
+ WebAuthnAbortService: () => WebAuthnAbortService
493
+ });
494
+ var init_esm = __esm(() => {
495
+ init_startRegistration();
496
+ init_startAuthentication();
497
+ init_browserSupportsWebAuthn();
498
+ init_platformAuthenticatorIsAvailable();
499
+ init_browserSupportsWebAuthnAutofill();
500
+ init_webAuthnAbortService();
501
+ init_webAuthnError();
502
+ init_types();
503
+ });
504
+
4
505
  // src/client/react.ts
5
506
  import { useCallback, useEffect, useRef, useState } from "react";
507
+
508
+ // src/client/passkeyHelpers.ts
509
+ var loadBrowser = async () => {
510
+ const mod = await Promise.resolve().then(() => (init_esm(), exports_esm));
511
+ return mod;
512
+ };
513
+ var errorFor = (caught) => ({
514
+ body: null,
515
+ message: caught instanceof Error ? caught.message : "webauthn_failed",
516
+ status: 0
517
+ });
518
+ var runConditionalAuthentication = async (client) => {
519
+ if (typeof window === "undefined" || !window.PublicKeyCredential) {
520
+ return {
521
+ data: null,
522
+ error: errorFor(new Error("webauthn_unavailable"))
523
+ };
524
+ }
525
+ const options = await client.passkeys.authenticateOptions();
526
+ if (options.error)
527
+ return { data: null, error: options.error };
528
+ try {
529
+ const { startAuthentication: startAuthentication3 } = await loadBrowser();
530
+ const credential = await startAuthentication3({
531
+ optionsJSON: options.data,
532
+ useBrowserAutofill: true
533
+ });
534
+ return client.passkeys.authenticateVerify(credential);
535
+ } catch (caught) {
536
+ return { data: null, error: errorFor(caught) };
537
+ }
538
+ };
539
+ var runPasskeyRegistration = async (client) => {
540
+ if (typeof window === "undefined" || !window.PublicKeyCredential) {
541
+ return {
542
+ data: null,
543
+ error: errorFor(new Error("webauthn_unavailable"))
544
+ };
545
+ }
546
+ const options = await client.passkeys.registerOptions();
547
+ if (options.error)
548
+ return { data: null, error: options.error };
549
+ try {
550
+ const { startRegistration: startRegistration3 } = await loadBrowser();
551
+ const credential = await startRegistration3({
552
+ optionsJSON: options.data
553
+ });
554
+ return client.passkeys.registerVerify(credential);
555
+ } catch (caught) {
556
+ return { data: null, error: errorFor(caught) };
557
+ }
558
+ };
559
+
560
+ // src/client/react.ts
6
561
  var useMutation = (run) => {
7
562
  const [data, setData] = useState(null);
8
563
  const [error, setError] = useState(null);
@@ -30,6 +585,58 @@ var useMutation = (run) => {
30
585
  return { data, error, isPending, mutate, reset };
31
586
  };
32
587
  var useMagicLink = (client) => useMutation(client.passwordless.requestMagicLink);
588
+ var usePasskeyAutofill = (client) => {
589
+ const [data, setData] = useState(null);
590
+ const [error, setError] = useState(null);
591
+ const [isPending, setIsPending] = useState(false);
592
+ const mountedRef = useRef(true);
593
+ useEffect(() => () => {
594
+ mountedRef.current = false;
595
+ }, []);
596
+ const start = useCallback(async () => {
597
+ setIsPending(true);
598
+ setError(null);
599
+ const result = await runConditionalAuthentication(client);
600
+ if (mountedRef.current) {
601
+ setData(result.data);
602
+ setError(result.error);
603
+ setIsPending(false);
604
+ }
605
+ }, [client]);
606
+ const cancel = useCallback(() => {
607
+ setIsPending(false);
608
+ }, []);
609
+ return { cancel, data, error, isPending, start };
610
+ };
611
+ var useUpgradeToPasskey = (client) => {
612
+ const [passkeys, setPasskeys] = useState(null);
613
+ const [error, setError] = useState(null);
614
+ const [isPending, setIsPending] = useState(true);
615
+ const mountedRef = useRef(true);
616
+ useEffect(() => () => {
617
+ mountedRef.current = false;
618
+ }, []);
619
+ const refetch = useCallback(async () => {
620
+ setIsPending(true);
621
+ const result = await client.passkeys.list();
622
+ if (mountedRef.current) {
623
+ setPasskeys(result.data);
624
+ setError(result.error);
625
+ setIsPending(false);
626
+ }
627
+ }, [client]);
628
+ useEffect(() => {
629
+ refetch();
630
+ }, [refetch]);
631
+ const register = useCallback(async () => {
632
+ const result = await runPasskeyRegistration(client);
633
+ if (result.error === null)
634
+ await refetch();
635
+ return result;
636
+ }, [client, refetch]);
637
+ const shouldPrompt = passkeys !== null && passkeys.length === 0;
638
+ return { error, isPending, passkeys, refetch, register, shouldPrompt };
639
+ };
33
640
  var useMfaChallenge = (client) => useMutation(client.mfa.challenge);
34
641
  var usePasswordReset = (client) => useMutation(client.passwordReset.request);
35
642
  var useSessions = (client) => {
@@ -64,14 +671,16 @@ var useSignIn = (client) => useMutation(client.signIn.email);
64
671
  var useSignOut = (client) => useMutation(client.signOut);
65
672
  var useSignUp = (client) => useMutation(client.signUp.email);
66
673
  export {
674
+ useUpgradeToPasskey,
67
675
  useSignUp,
68
676
  useSignOut,
69
677
  useSignIn,
70
678
  useSessions,
71
679
  usePasswordReset,
680
+ usePasskeyAutofill,
72
681
  useMfaChallenge,
73
682
  useMagicLink
74
683
  };
75
684
 
76
- //# debugId=A814F633A26BF2D664756E2164756E21
685
+ //# debugId=FA8CEE907CE1FBFC64756E2164756E21
77
686
  //# sourceMappingURL=react.js.map