@better-auth/passkey 1.5.6 → 1.6.0-beta.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.
@@ -0,0 +1,771 @@
1
+ import * as _simplewebauthn_server0 from "@simplewebauthn/server";
2
+ import { AuthenticationExtensionsClientInputs, AuthenticationResponseJSON, CredentialDeviceType, RegistrationResponseJSON, VerifiedAuthenticationResponse, VerifiedRegistrationResponse } from "@simplewebauthn/server";
3
+ import * as better_auth0 from "better-auth";
4
+ import { GenericEndpointContext } from "@better-auth/core";
5
+ import { InferOptionSchema } from "better-auth/types";
6
+ import * as better_call0 from "better-call";
7
+
8
+ //#region src/schema.d.ts
9
+ declare const schema: {
10
+ passkey: {
11
+ fields: {
12
+ name: {
13
+ type: "string";
14
+ required: false;
15
+ };
16
+ publicKey: {
17
+ type: "string";
18
+ required: true;
19
+ };
20
+ userId: {
21
+ type: "string";
22
+ references: {
23
+ model: string;
24
+ field: string;
25
+ };
26
+ required: true;
27
+ index: true;
28
+ };
29
+ credentialID: {
30
+ type: "string";
31
+ required: true;
32
+ index: true;
33
+ };
34
+ counter: {
35
+ type: "number";
36
+ required: true;
37
+ };
38
+ deviceType: {
39
+ type: "string";
40
+ required: true;
41
+ };
42
+ backedUp: {
43
+ type: "boolean";
44
+ required: true;
45
+ };
46
+ transports: {
47
+ type: "string";
48
+ required: false;
49
+ };
50
+ createdAt: {
51
+ type: "date";
52
+ required: false;
53
+ };
54
+ aaguid: {
55
+ type: "string";
56
+ required: false;
57
+ };
58
+ };
59
+ };
60
+ };
61
+ //#endregion
62
+ //#region src/types.d.ts
63
+ /**
64
+ * @internal
65
+ */
66
+ interface WebAuthnChallengeValue {
67
+ expectedChallenge: string;
68
+ userData: {
69
+ id: string;
70
+ name?: string | undefined;
71
+ displayName?: string | undefined;
72
+ };
73
+ context?: string | null;
74
+ }
75
+ type Awaitable<T> = T | Promise<T>;
76
+ interface PasskeyRegistrationUser {
77
+ id: string;
78
+ name: string;
79
+ displayName?: string | undefined;
80
+ }
81
+ type PasskeyExtensionsResolver = AuthenticationExtensionsClientInputs | ((args: {
82
+ ctx: GenericEndpointContext;
83
+ }) => Awaitable<AuthenticationExtensionsClientInputs | undefined>);
84
+ interface PasskeyRegistrationOptions {
85
+ /**
86
+ * Require an authenticated session for passkey registration.
87
+ *
88
+ * @default true
89
+ */
90
+ requireSession?: boolean | undefined;
91
+ /**
92
+ * Resolve the user when session is not available.
93
+ * Required when `requireSession` is false and no session exists.
94
+ */
95
+ resolveUser?: ((args: {
96
+ ctx: GenericEndpointContext;
97
+ context?: string | null | undefined;
98
+ }) => Awaitable<PasskeyRegistrationUser>) | undefined;
99
+ /**
100
+ * Callback after a successful registration verification.
101
+ * Useful for user linking or auditing.
102
+ */
103
+ afterVerification?: ((args: {
104
+ ctx: GenericEndpointContext;
105
+ verification: VerifiedRegistrationResponse;
106
+ user: PasskeyRegistrationUser;
107
+ clientData: RegistrationResponseJSON;
108
+ context?: string | null | undefined;
109
+ }) => Awaitable<{
110
+ userId?: string;
111
+ } | void>) | undefined;
112
+ /**
113
+ * Optional WebAuthn extensions to include in registration options.
114
+ */
115
+ extensions?: PasskeyExtensionsResolver | undefined;
116
+ }
117
+ interface PasskeyAuthenticationOptions {
118
+ /**
119
+ * Optional WebAuthn extensions to include in authentication options.
120
+ */
121
+ extensions?: PasskeyExtensionsResolver | undefined;
122
+ /**
123
+ * Callback after a successful authentication verification.
124
+ */
125
+ afterVerification?: ((args: {
126
+ ctx: GenericEndpointContext;
127
+ verification: VerifiedAuthenticationResponse;
128
+ clientData: AuthenticationResponseJSON;
129
+ }) => Awaitable<void>) | undefined;
130
+ }
131
+ interface PasskeyOptions {
132
+ /**
133
+ * A unique identifier for your website. 'localhost' is okay for
134
+ * local dev
135
+ *
136
+ * @default "localhost"
137
+ */
138
+ rpID?: string | undefined;
139
+ /**
140
+ * Human-readable title for your website
141
+ *
142
+ * @default "Better Auth"
143
+ */
144
+ rpName?: string | undefined;
145
+ /**
146
+ * The URL at which registrations and authentications should occur.
147
+ * `http://localhost` and `http://localhost:PORT` are also valid.
148
+ * Do NOT include any trailing /
149
+ *
150
+ * if this isn't provided. The client itself will
151
+ * pass this value.
152
+ */
153
+ origin?: (string | string[] | null) | undefined;
154
+ /**
155
+ * Allow customization of the authenticatorSelection options
156
+ * during passkey registration.
157
+ */
158
+ authenticatorSelection?: AuthenticatorSelectionCriteria | undefined;
159
+ /**
160
+ * Advanced options
161
+ */
162
+ advanced?: {
163
+ /**
164
+ * Cookie name for storing WebAuthn challenge ID during authentication flow
165
+ *
166
+ * @default "better-auth-passkey"
167
+ */
168
+ webAuthnChallengeCookie?: string;
169
+ } | undefined;
170
+ /**
171
+ * Schema for the passkey model
172
+ */
173
+ schema?: InferOptionSchema<typeof schema> | undefined;
174
+ /**
175
+ * Registration behavior overrides
176
+ */
177
+ registration?: PasskeyRegistrationOptions | undefined;
178
+ /**
179
+ * Authentication behavior overrides
180
+ */
181
+ authentication?: PasskeyAuthenticationOptions | undefined;
182
+ }
183
+ type Passkey = {
184
+ id: string;
185
+ name?: string | undefined;
186
+ publicKey: string;
187
+ userId: string;
188
+ credentialID: string;
189
+ counter: number;
190
+ deviceType: CredentialDeviceType;
191
+ backedUp: boolean;
192
+ transports?: string | undefined;
193
+ createdAt: Date;
194
+ aaguid?: string | undefined;
195
+ };
196
+ //#endregion
197
+ //#region src/error-codes.d.ts
198
+ declare const PASSKEY_ERROR_CODES: {
199
+ CHALLENGE_NOT_FOUND: better_auth0.RawError<"CHALLENGE_NOT_FOUND">;
200
+ YOU_ARE_NOT_ALLOWED_TO_REGISTER_THIS_PASSKEY: better_auth0.RawError<"YOU_ARE_NOT_ALLOWED_TO_REGISTER_THIS_PASSKEY">;
201
+ FAILED_TO_VERIFY_REGISTRATION: better_auth0.RawError<"FAILED_TO_VERIFY_REGISTRATION">;
202
+ PASSKEY_NOT_FOUND: better_auth0.RawError<"PASSKEY_NOT_FOUND">;
203
+ AUTHENTICATION_FAILED: better_auth0.RawError<"AUTHENTICATION_FAILED">;
204
+ UNABLE_TO_CREATE_SESSION: better_auth0.RawError<"UNABLE_TO_CREATE_SESSION">;
205
+ FAILED_TO_UPDATE_PASSKEY: better_auth0.RawError<"FAILED_TO_UPDATE_PASSKEY">;
206
+ PREVIOUSLY_REGISTERED: better_auth0.RawError<"PREVIOUSLY_REGISTERED">;
207
+ REGISTRATION_CANCELLED: better_auth0.RawError<"REGISTRATION_CANCELLED">;
208
+ AUTH_CANCELLED: better_auth0.RawError<"AUTH_CANCELLED">;
209
+ UNKNOWN_ERROR: better_auth0.RawError<"UNKNOWN_ERROR">;
210
+ SESSION_REQUIRED: better_auth0.RawError<"SESSION_REQUIRED">;
211
+ RESOLVE_USER_REQUIRED: better_auth0.RawError<"RESOLVE_USER_REQUIRED">;
212
+ RESOLVED_USER_INVALID: better_auth0.RawError<"RESOLVED_USER_INVALID">;
213
+ };
214
+ //#endregion
215
+ //#region src/index.d.ts
216
+ declare module "@better-auth/core" {
217
+ interface BetterAuthPluginRegistry<AuthOptions, Options> {
218
+ passkey: {
219
+ creator: typeof passkey;
220
+ };
221
+ }
222
+ }
223
+ declare const passkey: (options?: PasskeyOptions | undefined) => {
224
+ id: "passkey";
225
+ version: string;
226
+ endpoints: {
227
+ generatePasskeyRegistrationOptions: better_call0.Endpoint<"/passkey/generate-register-options", "GET", undefined, {
228
+ authenticatorAttachment?: "platform" | "cross-platform" | undefined;
229
+ name?: string | undefined;
230
+ context?: string | undefined;
231
+ } | undefined, [better_call0.Middleware<(inputContext: Record<string, any>) => Promise<{
232
+ session: {
233
+ session: Record<string, any> & {
234
+ id: string;
235
+ createdAt: Date;
236
+ updatedAt: Date;
237
+ userId: string;
238
+ expiresAt: Date;
239
+ token: string;
240
+ ipAddress?: string | null | undefined;
241
+ userAgent?: string | null | undefined;
242
+ };
243
+ user: Record<string, any> & {
244
+ id: string;
245
+ createdAt: Date;
246
+ updatedAt: Date;
247
+ email: string;
248
+ emailVerified: boolean;
249
+ name: string;
250
+ image?: string | null | undefined;
251
+ };
252
+ };
253
+ }>>], _simplewebauthn_server0.PublicKeyCredentialCreationOptionsJSON, {
254
+ openapi: {
255
+ operationId: string;
256
+ description: string;
257
+ responses: {
258
+ 200: {
259
+ description: string;
260
+ parameters: {
261
+ query: {
262
+ authenticatorAttachment: {
263
+ description: string;
264
+ required: boolean;
265
+ };
266
+ name: {
267
+ description: string;
268
+ required: boolean;
269
+ };
270
+ context: {
271
+ description: string;
272
+ required: boolean;
273
+ };
274
+ };
275
+ };
276
+ content: {
277
+ "application/json": {
278
+ schema: {
279
+ type: "object";
280
+ properties: {
281
+ challenge: {
282
+ type: string;
283
+ };
284
+ rp: {
285
+ type: string;
286
+ properties: {
287
+ name: {
288
+ type: string;
289
+ };
290
+ id: {
291
+ type: string;
292
+ };
293
+ };
294
+ };
295
+ user: {
296
+ type: string;
297
+ properties: {
298
+ id: {
299
+ type: string;
300
+ };
301
+ name: {
302
+ type: string;
303
+ };
304
+ displayName: {
305
+ type: string;
306
+ };
307
+ };
308
+ };
309
+ pubKeyCredParams: {
310
+ type: string;
311
+ items: {
312
+ type: string;
313
+ properties: {
314
+ type: {
315
+ type: string;
316
+ };
317
+ alg: {
318
+ type: string;
319
+ };
320
+ };
321
+ };
322
+ };
323
+ timeout: {
324
+ type: string;
325
+ };
326
+ excludeCredentials: {
327
+ type: string;
328
+ items: {
329
+ type: string;
330
+ properties: {
331
+ id: {
332
+ type: string;
333
+ };
334
+ type: {
335
+ type: string;
336
+ };
337
+ transports: {
338
+ type: string;
339
+ items: {
340
+ type: string;
341
+ };
342
+ };
343
+ };
344
+ };
345
+ };
346
+ authenticatorSelection: {
347
+ type: string;
348
+ properties: {
349
+ authenticatorAttachment: {
350
+ type: string;
351
+ };
352
+ requireResidentKey: {
353
+ type: string;
354
+ };
355
+ userVerification: {
356
+ type: string;
357
+ };
358
+ };
359
+ };
360
+ attestation: {
361
+ type: string;
362
+ };
363
+ extensions: {
364
+ type: string;
365
+ };
366
+ };
367
+ };
368
+ };
369
+ };
370
+ };
371
+ };
372
+ };
373
+ }, undefined>;
374
+ generatePasskeyAuthenticationOptions: better_call0.Endpoint<"/passkey/generate-authenticate-options", "GET", undefined, Record<string, any> | undefined, [], _simplewebauthn_server0.PublicKeyCredentialRequestOptionsJSON, {
375
+ openapi: {
376
+ operationId: string;
377
+ description: string;
378
+ responses: {
379
+ 200: {
380
+ description: string;
381
+ content: {
382
+ "application/json": {
383
+ schema: {
384
+ type: "object";
385
+ properties: {
386
+ challenge: {
387
+ type: string;
388
+ };
389
+ rp: {
390
+ type: string;
391
+ properties: {
392
+ name: {
393
+ type: string;
394
+ };
395
+ id: {
396
+ type: string;
397
+ };
398
+ };
399
+ };
400
+ user: {
401
+ type: string;
402
+ properties: {
403
+ id: {
404
+ type: string;
405
+ };
406
+ name: {
407
+ type: string;
408
+ };
409
+ displayName: {
410
+ type: string;
411
+ };
412
+ };
413
+ };
414
+ timeout: {
415
+ type: string;
416
+ };
417
+ allowCredentials: {
418
+ type: string;
419
+ items: {
420
+ type: string;
421
+ properties: {
422
+ id: {
423
+ type: string;
424
+ };
425
+ type: {
426
+ type: string;
427
+ };
428
+ transports: {
429
+ type: string;
430
+ items: {
431
+ type: string;
432
+ };
433
+ };
434
+ };
435
+ };
436
+ };
437
+ userVerification: {
438
+ type: string;
439
+ };
440
+ authenticatorSelection: {
441
+ type: string;
442
+ properties: {
443
+ authenticatorAttachment: {
444
+ type: string;
445
+ };
446
+ requireResidentKey: {
447
+ type: string;
448
+ };
449
+ userVerification: {
450
+ type: string;
451
+ };
452
+ };
453
+ };
454
+ extensions: {
455
+ type: string;
456
+ };
457
+ };
458
+ };
459
+ };
460
+ };
461
+ };
462
+ };
463
+ };
464
+ }, undefined>;
465
+ verifyPasskeyRegistration: better_call0.Endpoint<"/passkey/verify-registration", "POST", {
466
+ response: any;
467
+ name?: string | undefined;
468
+ }, Record<string, any> | undefined, [better_call0.Middleware<(inputContext: Record<string, any>) => Promise<{
469
+ session: {
470
+ session: Record<string, any> & {
471
+ id: string;
472
+ createdAt: Date;
473
+ updatedAt: Date;
474
+ userId: string;
475
+ expiresAt: Date;
476
+ token: string;
477
+ ipAddress?: string | null | undefined;
478
+ userAgent?: string | null | undefined;
479
+ };
480
+ user: Record<string, any> & {
481
+ id: string;
482
+ createdAt: Date;
483
+ updatedAt: Date;
484
+ email: string;
485
+ emailVerified: boolean;
486
+ name: string;
487
+ image?: string | null | undefined;
488
+ };
489
+ };
490
+ }>>], Passkey, {
491
+ openapi: {
492
+ operationId: string;
493
+ description: string;
494
+ responses: {
495
+ 200: {
496
+ description: string;
497
+ content: {
498
+ "application/json": {
499
+ schema: {
500
+ $ref: string;
501
+ };
502
+ };
503
+ };
504
+ };
505
+ 400: {
506
+ description: string;
507
+ };
508
+ };
509
+ };
510
+ }, undefined>;
511
+ verifyPasskeyAuthentication: better_call0.Endpoint<"/passkey/verify-authentication", "POST", {
512
+ response: _simplewebauthn_server0.AuthenticationResponseJSON;
513
+ }, Record<string, any> | undefined, [], {
514
+ session: {
515
+ id: string;
516
+ createdAt: Date;
517
+ updatedAt: Date;
518
+ userId: string;
519
+ expiresAt: Date;
520
+ token: string;
521
+ ipAddress?: string | null | undefined;
522
+ userAgent?: string | null | undefined;
523
+ };
524
+ }, {
525
+ openapi: {
526
+ operationId: string;
527
+ description: string;
528
+ responses: {
529
+ 200: {
530
+ description: string;
531
+ content: {
532
+ "application/json": {
533
+ schema: {
534
+ type: "object";
535
+ properties: {
536
+ session: {
537
+ $ref: string;
538
+ };
539
+ user: {
540
+ $ref: string;
541
+ };
542
+ };
543
+ };
544
+ };
545
+ };
546
+ };
547
+ };
548
+ };
549
+ $Infer: {
550
+ body: {
551
+ response: _simplewebauthn_server0.AuthenticationResponseJSON;
552
+ };
553
+ };
554
+ }, undefined>;
555
+ listPasskeys: better_call0.Endpoint<"/passkey/list-user-passkeys", "GET", undefined, Record<string, any> | undefined, [better_call0.Middleware<(inputContext: Record<string, any>) => Promise<{
556
+ session: {
557
+ session: Record<string, any> & {
558
+ id: string;
559
+ createdAt: Date;
560
+ updatedAt: Date;
561
+ userId: string;
562
+ expiresAt: Date;
563
+ token: string;
564
+ ipAddress?: string | null | undefined;
565
+ userAgent?: string | null | undefined;
566
+ };
567
+ user: Record<string, any> & {
568
+ id: string;
569
+ createdAt: Date;
570
+ updatedAt: Date;
571
+ email: string;
572
+ emailVerified: boolean;
573
+ name: string;
574
+ image?: string | null | undefined;
575
+ };
576
+ };
577
+ }>>], Passkey[], {
578
+ openapi: {
579
+ description: string;
580
+ responses: {
581
+ "200": {
582
+ description: string;
583
+ content: {
584
+ "application/json": {
585
+ schema: {
586
+ type: "array";
587
+ items: {
588
+ $ref: string;
589
+ required: string[];
590
+ };
591
+ description: string;
592
+ };
593
+ };
594
+ };
595
+ };
596
+ };
597
+ };
598
+ }, undefined>;
599
+ deletePasskey: better_call0.Endpoint<"/passkey/delete-passkey", "POST", {
600
+ id: string;
601
+ }, Record<string, any> | undefined, [better_call0.Middleware<(inputContext: Record<string, any>) => Promise<{
602
+ session: {
603
+ session: Record<string, any> & {
604
+ id: string;
605
+ createdAt: Date;
606
+ updatedAt: Date;
607
+ userId: string;
608
+ expiresAt: Date;
609
+ token: string;
610
+ ipAddress?: string | null | undefined;
611
+ userAgent?: string | null | undefined;
612
+ };
613
+ user: Record<string, any> & {
614
+ id: string;
615
+ createdAt: Date;
616
+ updatedAt: Date;
617
+ email: string;
618
+ emailVerified: boolean;
619
+ name: string;
620
+ image?: string | null | undefined;
621
+ };
622
+ };
623
+ }>>], {
624
+ status: boolean;
625
+ }, {
626
+ openapi: {
627
+ description: string;
628
+ responses: {
629
+ "200": {
630
+ description: string;
631
+ content: {
632
+ "application/json": {
633
+ schema: {
634
+ type: "object";
635
+ properties: {
636
+ status: {
637
+ type: string;
638
+ description: string;
639
+ };
640
+ };
641
+ required: string[];
642
+ };
643
+ };
644
+ };
645
+ };
646
+ };
647
+ };
648
+ }, undefined>;
649
+ updatePasskey: better_call0.Endpoint<"/passkey/update-passkey", "POST", {
650
+ id: string;
651
+ name: string;
652
+ }, Record<string, any> | undefined, [better_call0.Middleware<(inputContext: Record<string, any>) => Promise<{
653
+ session: {
654
+ session: Record<string, any> & {
655
+ id: string;
656
+ createdAt: Date;
657
+ updatedAt: Date;
658
+ userId: string;
659
+ expiresAt: Date;
660
+ token: string;
661
+ ipAddress?: string | null | undefined;
662
+ userAgent?: string | null | undefined;
663
+ };
664
+ user: Record<string, any> & {
665
+ id: string;
666
+ createdAt: Date;
667
+ updatedAt: Date;
668
+ email: string;
669
+ emailVerified: boolean;
670
+ name: string;
671
+ image?: string | null | undefined;
672
+ };
673
+ };
674
+ }>>], {
675
+ passkey: Passkey;
676
+ }, {
677
+ openapi: {
678
+ description: string;
679
+ responses: {
680
+ "200": {
681
+ description: string;
682
+ content: {
683
+ "application/json": {
684
+ schema: {
685
+ type: "object";
686
+ properties: {
687
+ passkey: {
688
+ $ref: string;
689
+ };
690
+ };
691
+ required: string[];
692
+ };
693
+ };
694
+ };
695
+ };
696
+ };
697
+ };
698
+ }, undefined>;
699
+ };
700
+ schema: {
701
+ passkey: {
702
+ fields: {
703
+ name: {
704
+ type: "string";
705
+ required: false;
706
+ };
707
+ publicKey: {
708
+ type: "string";
709
+ required: true;
710
+ };
711
+ userId: {
712
+ type: "string";
713
+ references: {
714
+ model: string;
715
+ field: string;
716
+ };
717
+ required: true;
718
+ index: true;
719
+ };
720
+ credentialID: {
721
+ type: "string";
722
+ required: true;
723
+ index: true;
724
+ };
725
+ counter: {
726
+ type: "number";
727
+ required: true;
728
+ };
729
+ deviceType: {
730
+ type: "string";
731
+ required: true;
732
+ };
733
+ backedUp: {
734
+ type: "boolean";
735
+ required: true;
736
+ };
737
+ transports: {
738
+ type: "string";
739
+ required: false;
740
+ };
741
+ createdAt: {
742
+ type: "date";
743
+ required: false;
744
+ };
745
+ aaguid: {
746
+ type: "string";
747
+ required: false;
748
+ };
749
+ };
750
+ };
751
+ };
752
+ $ERROR_CODES: {
753
+ CHALLENGE_NOT_FOUND: better_auth0.RawError<"CHALLENGE_NOT_FOUND">;
754
+ YOU_ARE_NOT_ALLOWED_TO_REGISTER_THIS_PASSKEY: better_auth0.RawError<"YOU_ARE_NOT_ALLOWED_TO_REGISTER_THIS_PASSKEY">;
755
+ FAILED_TO_VERIFY_REGISTRATION: better_auth0.RawError<"FAILED_TO_VERIFY_REGISTRATION">;
756
+ PASSKEY_NOT_FOUND: better_auth0.RawError<"PASSKEY_NOT_FOUND">;
757
+ AUTHENTICATION_FAILED: better_auth0.RawError<"AUTHENTICATION_FAILED">;
758
+ UNABLE_TO_CREATE_SESSION: better_auth0.RawError<"UNABLE_TO_CREATE_SESSION">;
759
+ FAILED_TO_UPDATE_PASSKEY: better_auth0.RawError<"FAILED_TO_UPDATE_PASSKEY">;
760
+ PREVIOUSLY_REGISTERED: better_auth0.RawError<"PREVIOUSLY_REGISTERED">;
761
+ REGISTRATION_CANCELLED: better_auth0.RawError<"REGISTRATION_CANCELLED">;
762
+ AUTH_CANCELLED: better_auth0.RawError<"AUTH_CANCELLED">;
763
+ UNKNOWN_ERROR: better_auth0.RawError<"UNKNOWN_ERROR">;
764
+ SESSION_REQUIRED: better_auth0.RawError<"SESSION_REQUIRED">;
765
+ RESOLVE_USER_REQUIRED: better_auth0.RawError<"RESOLVE_USER_REQUIRED">;
766
+ RESOLVED_USER_INVALID: better_auth0.RawError<"RESOLVED_USER_INVALID">;
767
+ };
768
+ options: PasskeyOptions | undefined;
769
+ };
770
+ //#endregion
771
+ export { PasskeyExtensionsResolver as a, PasskeyRegistrationUser as c, PasskeyAuthenticationOptions as i, WebAuthnChallengeValue as l, PASSKEY_ERROR_CODES as n, PasskeyOptions as o, Passkey as r, PasskeyRegistrationOptions as s, passkey as t };