@better-auth/passkey 1.4.4-beta.1 → 1.4.4-beta.3

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