@better-auth/passkey 1.7.0-beta.5 → 1.7.0-beta.6

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 { a as Passkey, c as PasskeyOptions, d as WebAuthnChallengeValue, l as PasskeyRegistrationOptions, n as PASSKEY_ERROR_CODES, o as PasskeyAuthenticationOptions, s as PasskeyExtensionsResolver, t as passkey, u as PasskeyRegistrationUser } from "./index-Ci52vhOT.mjs";
1
+ import { a as Passkey, c as PasskeyOptions, d as WebAuthnChallengeValue, l as PasskeyRegistrationOptions, n as PASSKEY_ERROR_CODES, o as PasskeyAuthenticationOptions, s as PasskeyExtensionsResolver, t as passkey, u as PasskeyRegistrationUser } from "./index-z0BvlclO.mjs";
2
2
  import { AuthenticationExtensionsClientInputs, AuthenticationExtensionsClientOutputs, AuthenticationResponseJSON, RegistrationResponseJSON } from "@simplewebauthn/server";
3
3
  import * as better_auth_client0 from "better-auth/client";
4
4
  import * as nanostores from "nanostores";
package/dist/client.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { n as PASSKEY_ERROR_CODES, t as PACKAGE_VERSION } from "./version-tMqL0F6x.mjs";
1
+ import { n as PASSKEY_ERROR_CODES, t as PACKAGE_VERSION } from "./version-DvfQNSl9.mjs";
2
2
  import { WebAuthnError, startAuthentication, startRegistration } from "@simplewebauthn/browser";
3
3
  import { useAuthQuery } from "better-auth/client";
4
4
  import { atom } from "nanostores";
@@ -294,25 +294,10 @@ declare const passkey: (options?: PasskeyOptions | undefined) => {
294
294
  openapi: {
295
295
  operationId: string;
296
296
  description: string;
297
+ parameters: better_call0.OpenAPIParameter[];
297
298
  responses: {
298
299
  200: {
299
300
  description: string;
300
- parameters: {
301
- query: {
302
- authenticatorAttachment: {
303
- description: string;
304
- required: boolean;
305
- };
306
- name: {
307
- description: string;
308
- required: boolean;
309
- };
310
- context: {
311
- description: string;
312
- required: boolean;
313
- };
314
- };
315
- };
316
301
  content: {
317
302
  "application/json": {
318
303
  schema: {
package/dist/index.d.mts CHANGED
@@ -1,2 +1,2 @@
1
- import { a as Passkey, c as PasskeyOptions, i as getAuthenticatorName, n as PASSKEY_ERROR_CODES, r as commonAuthenticatorNames, t as passkey } from "./index-Ci52vhOT.mjs";
1
+ import { a as Passkey, c as PasskeyOptions, i as getAuthenticatorName, n as PASSKEY_ERROR_CODES, r as commonAuthenticatorNames, t as passkey } from "./index-z0BvlclO.mjs";
2
2
  export { PASSKEY_ERROR_CODES, Passkey, PasskeyOptions, commonAuthenticatorNames, getAuthenticatorName, passkey };
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { n as PASSKEY_ERROR_CODES, t as PACKAGE_VERSION } from "./version-tMqL0F6x.mjs";
1
+ import { n as PASSKEY_ERROR_CODES, t as PACKAGE_VERSION } from "./version-DvfQNSl9.mjs";
2
2
  import { mergeSchema } from "better-auth/db";
3
3
  import { createAuthEndpoint } from "@better-auth/core/api";
4
4
  import { APIError } from "@better-auth/core/error";
@@ -52,6 +52,35 @@ const generatePasskeyQuerySchema = z.object({
52
52
  name: z.string().optional(),
53
53
  context: z.string().optional()
54
54
  }).optional();
55
+ const generatePasskeyRegistrationOptionsOpenAPIParameters = [
56
+ {
57
+ name: "authenticatorAttachment",
58
+ in: "query",
59
+ required: false,
60
+ description: `Type of authenticator to use for registration.
61
+ "platform" for device-specific authenticators,
62
+ "cross-platform" for authenticators that can be used across devices.`,
63
+ schema: {
64
+ type: "string",
65
+ enum: ["platform", "cross-platform"]
66
+ }
67
+ },
68
+ {
69
+ name: "name",
70
+ in: "query",
71
+ required: false,
72
+ description: `Optional custom name for the passkey.
73
+ This can help identify the passkey when managing multiple credentials.`,
74
+ schema: { type: "string" }
75
+ },
76
+ {
77
+ name: "context",
78
+ in: "query",
79
+ required: false,
80
+ description: "Optional context for passkey-first registration flows.",
81
+ schema: { type: "string" }
82
+ }
83
+ ];
55
84
  const generatePasskeyRegistrationOptions = (opts, { maxAgeInSeconds }) => {
56
85
  return createAuthEndpoint("/passkey/generate-register-options", {
57
86
  method: "GET",
@@ -60,25 +89,9 @@ const generatePasskeyRegistrationOptions = (opts, { maxAgeInSeconds }) => {
60
89
  metadata: { openapi: {
61
90
  operationId: "generatePasskeyRegistrationOptions",
62
91
  description: "Generate registration options for a new passkey",
92
+ parameters: generatePasskeyRegistrationOptionsOpenAPIParameters,
63
93
  responses: { 200: {
64
94
  description: "Success",
65
- parameters: { query: {
66
- authenticatorAttachment: {
67
- description: `Type of authenticator to use for registration.
68
- "platform" for device-specific authenticators,
69
- "cross-platform" for authenticators that can be used across devices.`,
70
- required: false
71
- },
72
- name: {
73
- description: `Optional custom name for the passkey.
74
- This can help identify the passkey when managing multiple credentials.`,
75
- required: false
76
- },
77
- context: {
78
- description: "Optional context for passkey-first registration flows.",
79
- required: false
80
- }
81
- } },
82
95
  content: { "application/json": { schema: {
83
96
  type: "object",
84
97
  properties: {
@@ -178,6 +191,7 @@ const generatePasskeyRegistrationOptions = (opts, { maxAgeInSeconds }) => {
178
191
  await ctx.context.internalAdapter.createVerificationValue({
179
192
  identifier: verificationToken,
180
193
  value: JSON.stringify({
194
+ type: "registration",
181
195
  expectedChallenge: options.challenge,
182
196
  userData: {
183
197
  id: user.id,
@@ -268,6 +282,7 @@ const generatePasskeyAuthenticationOptions = (opts, { maxAgeInSeconds }) => crea
268
282
  })) } : {}
269
283
  });
270
284
  const data = {
285
+ type: "authentication",
271
286
  expectedChallenge: options.challenge,
272
287
  userData: { id: session?.user.id || "" }
273
288
  };
@@ -315,7 +330,8 @@ const verifyPasskeyRegistration = (options) => {
315
330
  if (!verificationToken) throw APIError.from("BAD_REQUEST", PASSKEY_ERROR_CODES.CHALLENGE_NOT_FOUND);
316
331
  const data = await ctx.context.internalAdapter.consumeVerificationValue(verificationToken);
317
332
  if (!data) throw APIError.from("BAD_REQUEST", PASSKEY_ERROR_CODES.CHALLENGE_NOT_FOUND);
318
- const { expectedChallenge, userData, context } = JSON.parse(data.value);
333
+ const { type: ceremony, expectedChallenge, userData, context } = JSON.parse(data.value);
334
+ if (ceremony !== "registration") throw APIError.from("BAD_REQUEST", PASSKEY_ERROR_CODES.CHALLENGE_NOT_FOUND);
319
335
  const session = requireSession ? ctx.context.session : await getSessionFromCtx(ctx);
320
336
  if (session?.user?.id && userData.id !== session.user.id) throw APIError.from("UNAUTHORIZED", PASSKEY_ERROR_CODES.YOU_ARE_NOT_ALLOWED_TO_REGISTER_THIS_PASSKEY);
321
337
  try {
@@ -351,6 +367,7 @@ const verifyPasskeyRegistration = (options) => {
351
367
  }
352
368
  if (!resolvedName) resolvedName = result?.name?.trim() || void 0;
353
369
  }
370
+ if (!targetUserId) throw APIError.from("BAD_REQUEST", PASSKEY_ERROR_CODES.RESOLVED_USER_INVALID);
354
371
  const pubKey = base64.encode(credential.publicKey);
355
372
  const newPasskey = {
356
373
  name: resolvedName,
@@ -406,7 +423,8 @@ const verifyPasskeyAuthentication = (options) => createAuthEndpoint("/passkey/ve
406
423
  if (!verificationToken) throw APIError.from("BAD_REQUEST", PASSKEY_ERROR_CODES.CHALLENGE_NOT_FOUND);
407
424
  const data = await ctx.context.internalAdapter.consumeVerificationValue(verificationToken);
408
425
  if (!data) throw APIError.from("BAD_REQUEST", PASSKEY_ERROR_CODES.CHALLENGE_NOT_FOUND);
409
- const { expectedChallenge } = JSON.parse(data.value);
426
+ const { type: ceremony, expectedChallenge } = JSON.parse(data.value);
427
+ if (ceremony !== "authentication") throw APIError.from("BAD_REQUEST", PASSKEY_ERROR_CODES.CHALLENGE_NOT_FOUND);
410
428
  const passkey = await ctx.context.adapter.findOne({
411
429
  model: "passkey",
412
430
  where: [{
@@ -18,6 +18,6 @@ const PASSKEY_ERROR_CODES = defineErrorCodes({
18
18
  });
19
19
  //#endregion
20
20
  //#region src/version.ts
21
- const PACKAGE_VERSION = "1.7.0-beta.5";
21
+ const PACKAGE_VERSION = "1.7.0-beta.6";
22
22
  //#endregion
23
23
  export { PASSKEY_ERROR_CODES as n, PACKAGE_VERSION as t };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@better-auth/passkey",
3
- "version": "1.7.0-beta.5",
3
+ "version": "1.7.0-beta.6",
4
4
  "description": "Passkey plugin for Better Auth",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -55,16 +55,16 @@
55
55
  },
56
56
  "devDependencies": {
57
57
  "tsdown": "0.21.1",
58
- "@better-auth/core": "1.7.0-beta.5",
59
- "better-auth": "1.7.0-beta.5"
58
+ "@better-auth/core": "1.7.0-beta.6",
59
+ "better-auth": "1.7.0-beta.6"
60
60
  },
61
61
  "peerDependencies": {
62
- "@better-auth/utils": "0.4.1",
63
- "@better-fetch/fetch": "1.2.2",
62
+ "@better-auth/utils": "0.4.2",
63
+ "@better-fetch/fetch": "1.3.1",
64
64
  "better-call": "1.3.6",
65
65
  "nanostores": "^1.0.1",
66
- "@better-auth/core": "^1.7.0-beta.5",
67
- "better-auth": "^1.7.0-beta.5"
66
+ "@better-auth/core": "^1.7.0-beta.6",
67
+ "better-auth": "^1.7.0-beta.6"
68
68
  },
69
69
  "scripts": {
70
70
  "build": "tsdown",