better-auth 1.7.2 → 1.7.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.
Files changed (63) hide show
  1. package/dist/api/index.d.mts +6 -22
  2. package/dist/api/index.mjs +2 -0
  3. package/dist/api/routes/account.d.mts +1 -9
  4. package/dist/api/routes/account.mjs +0 -6
  5. package/dist/api/routes/callback.mjs +0 -2
  6. package/dist/api/routes/password.mjs +0 -2
  7. package/dist/api/routes/session.mjs +12 -5
  8. package/dist/api/routes/sign-in.d.mts +2 -2
  9. package/dist/api/routes/sign-in.mjs +1 -5
  10. package/dist/api/routes/sign-up.mjs +0 -2
  11. package/dist/api/routes/update-user.mjs +0 -2
  12. package/dist/api/to-auth-endpoints.mjs +2 -0
  13. package/dist/auth/base.mjs +13 -1
  14. package/dist/auth/trusted-origins.mjs +6 -4
  15. package/dist/client/config.d.mts +2 -0
  16. package/dist/client/config.mjs +1 -0
  17. package/dist/client/vue/index.d.mts +31 -20
  18. package/dist/client/vue/index.mjs +23 -5
  19. package/dist/context/create-context.mjs +2 -0
  20. package/dist/cookies/session-store.d.mts +0 -1
  21. package/dist/cookies/session-store.mjs +16 -5
  22. package/dist/db/adapter-kysely.mjs +1 -2
  23. package/dist/db/get-migration.d.mts +1 -0
  24. package/dist/db/get-migration.mjs +10 -32
  25. package/dist/db/internal-adapter.mjs +14 -17
  26. package/dist/db/schema.d.mts +0 -1
  27. package/dist/index.mjs +0 -1
  28. package/dist/oauth2/account-key.mjs +1 -5
  29. package/dist/oauth2/link-account.d.mts +0 -1
  30. package/dist/oauth2/link-account.mjs +5 -11
  31. package/dist/package.mjs +1 -1
  32. package/dist/plugins/admin/routes.mjs +0 -3
  33. package/dist/plugins/device-authorization/index.d.mts +11 -11
  34. package/dist/plugins/email-otp/routes.mjs +0 -2
  35. package/dist/plugins/generic-oauth/index.mjs +14 -10
  36. package/dist/plugins/generic-oauth/providers/auth0.mjs +2 -4
  37. package/dist/plugins/generic-oauth/providers/keycloak.mjs +6 -9
  38. package/dist/plugins/generic-oauth/providers/line.mjs +0 -1
  39. package/dist/plugins/generic-oauth/providers/okta.mjs +6 -9
  40. package/dist/plugins/generic-oauth/providers/slack.mjs +0 -1
  41. package/dist/plugins/generic-oauth/types.d.mts +0 -9
  42. package/dist/plugins/haveibeenpwned/index.d.mts +9 -1
  43. package/dist/plugins/haveibeenpwned/index.mjs +31 -11
  44. package/dist/plugins/index.d.mts +2 -2
  45. package/dist/plugins/index.mjs +2 -2
  46. package/dist/plugins/last-login-method/index.mjs +1 -0
  47. package/dist/plugins/oauth-proxy/index.d.mts +17 -0
  48. package/dist/plugins/oauth-proxy/index.mjs +145 -99
  49. package/dist/plugins/one-tap/index.mjs +0 -1
  50. package/dist/plugins/open-api/generator.mjs +15 -1
  51. package/dist/plugins/open-api/index.mjs +0 -1
  52. package/dist/plugins/organization/has-permission.mjs +4 -2
  53. package/dist/plugins/phone-number/routes.mjs +0 -3
  54. package/dist/plugins/siwe/index.mjs +0 -3
  55. package/dist/plugins/two-factor/client.d.mts +1 -0
  56. package/dist/plugins/two-factor/error-code.d.mts +1 -0
  57. package/dist/plugins/two-factor/error-code.mjs +1 -0
  58. package/dist/plugins/two-factor/index.d.mts +1 -0
  59. package/dist/plugins/two-factor/index.mjs +3 -2
  60. package/dist/state.d.mts +0 -13
  61. package/dist/test-utils/test-instance.mjs +10 -9
  62. package/package.json +9 -9
  63. package/dist/utils/index.mjs +0 -5
@@ -6,7 +6,6 @@ import { PACKAGE_VERSION } from "../../version.mjs";
6
6
  import { toChecksumAddress } from "../../utils/hashing.mjs";
7
7
  import { normalizeSiweDomain, parseSiweMessage } from "./parse-message.mjs";
8
8
  import { schema } from "./schema.mjs";
9
- import { createLocalAccountIssuer } from "@better-auth/core/db";
10
9
  import { createAuthEndpoint } from "@better-auth/core/api";
11
10
  import * as z from "zod";
12
11
  import { createPlaceholderEmail } from "@better-auth/core/utils/email";
@@ -215,7 +214,6 @@ const siwe = (options) => {
215
214
  await ctx.context.internalAdapter.createAccount({
216
215
  userId: user.id,
217
216
  providerId: "siwe",
218
- issuer: createLocalAccountIssuer("siwe"),
219
217
  accountId: `${walletAddress}:${chainId}`,
220
218
  createdAt: /* @__PURE__ */ new Date(),
221
219
  updatedAt: /* @__PURE__ */ new Date()
@@ -234,7 +232,6 @@ const siwe = (options) => {
234
232
  await ctx.context.internalAdapter.createAccount({
235
233
  userId: user.id,
236
234
  providerId: "siwe",
237
- issuer: createLocalAccountIssuer("siwe"),
238
235
  accountId: `${walletAddress}:${chainId}`,
239
236
  createdAt: /* @__PURE__ */ new Date(),
240
237
  updatedAt: /* @__PURE__ */ new Date()
@@ -61,6 +61,7 @@ declare const twoFactorClient: (options?: {
61
61
  OTP_NOT_CONFIGURED: _$_better_auth_core_utils_error_codes0.RawError<"OTP_NOT_CONFIGURED">;
62
62
  OTP_HAS_EXPIRED: _$_better_auth_core_utils_error_codes0.RawError<"OTP_HAS_EXPIRED">;
63
63
  TOTP_NOT_ENABLED: _$_better_auth_core_utils_error_codes0.RawError<"TOTP_NOT_ENABLED">;
64
+ TOTP_ALREADY_ENABLED: _$_better_auth_core_utils_error_codes0.RawError<"TOTP_ALREADY_ENABLED">;
64
65
  TOTP_NOT_CONFIGURED: _$_better_auth_core_utils_error_codes0.RawError<"TOTP_NOT_CONFIGURED">;
65
66
  TWO_FACTOR_NOT_ENABLED: _$_better_auth_core_utils_error_codes0.RawError<"TWO_FACTOR_NOT_ENABLED">;
66
67
  BACKUP_CODES_NOT_ENABLED: _$_better_auth_core_utils_error_codes0.RawError<"BACKUP_CODES_NOT_ENABLED">;
@@ -6,6 +6,7 @@ declare const TWO_FACTOR_ERROR_CODES: {
6
6
  OTP_NOT_CONFIGURED: _$_better_auth_core_utils_error_codes0.RawError<"OTP_NOT_CONFIGURED">;
7
7
  OTP_HAS_EXPIRED: _$_better_auth_core_utils_error_codes0.RawError<"OTP_HAS_EXPIRED">;
8
8
  TOTP_NOT_ENABLED: _$_better_auth_core_utils_error_codes0.RawError<"TOTP_NOT_ENABLED">;
9
+ TOTP_ALREADY_ENABLED: _$_better_auth_core_utils_error_codes0.RawError<"TOTP_ALREADY_ENABLED">;
9
10
  TOTP_NOT_CONFIGURED: _$_better_auth_core_utils_error_codes0.RawError<"TOTP_NOT_CONFIGURED">;
10
11
  TWO_FACTOR_NOT_ENABLED: _$_better_auth_core_utils_error_codes0.RawError<"TWO_FACTOR_NOT_ENABLED">;
11
12
  BACKUP_CODES_NOT_ENABLED: _$_better_auth_core_utils_error_codes0.RawError<"BACKUP_CODES_NOT_ENABLED">;
@@ -5,6 +5,7 @@ const TWO_FACTOR_ERROR_CODES = defineErrorCodes({
5
5
  OTP_NOT_CONFIGURED: "OTP is not available",
6
6
  OTP_HAS_EXPIRED: "OTP has expired",
7
7
  TOTP_NOT_ENABLED: "TOTP not enabled",
8
+ TOTP_ALREADY_ENABLED: "TOTP is already enabled",
8
9
  TOTP_NOT_CONFIGURED: "TOTP is not available",
9
10
  TWO_FACTOR_NOT_ENABLED: "Two factor isn't enabled",
10
11
  BACKUP_CODES_NOT_ENABLED: "Backup codes aren't enabled",
@@ -705,6 +705,7 @@ declare const twoFactor: <O extends TwoFactorOptions>(options?: O) => {
705
705
  OTP_NOT_CONFIGURED: _$_better_auth_core_utils_error_codes0.RawError<"OTP_NOT_CONFIGURED">;
706
706
  OTP_HAS_EXPIRED: _$_better_auth_core_utils_error_codes0.RawError<"OTP_HAS_EXPIRED">;
707
707
  TOTP_NOT_ENABLED: _$_better_auth_core_utils_error_codes0.RawError<"TOTP_NOT_ENABLED">;
708
+ TOTP_ALREADY_ENABLED: _$_better_auth_core_utils_error_codes0.RawError<"TOTP_ALREADY_ENABLED">;
708
709
  TOTP_NOT_CONFIGURED: _$_better_auth_core_utils_error_codes0.RawError<"TOTP_NOT_CONFIGURED">;
709
710
  TWO_FACTOR_NOT_ENABLED: _$_better_auth_core_utils_error_codes0.RawError<"TWO_FACTOR_NOT_ENABLED">;
710
711
  BACKUP_CODES_NOT_ENABLED: _$_better_auth_core_utils_error_codes0.RawError<"BACKUP_CODES_NOT_ENABLED">;
@@ -122,7 +122,6 @@ const twoFactor = (options) => {
122
122
  await ctx.context.internalAdapter.deleteSession(ctx.context.session.session.token);
123
123
  return ctx.json({ method: "otp" });
124
124
  }
125
- const backupCodes = await generateBackupCodes(ctx.context.secretConfig, backupCodeOptions);
126
125
  const existingTwoFactor = await ctx.context.adapter.findOne({
127
126
  model: opts.twoFactorTable,
128
127
  where: [{
@@ -130,6 +129,8 @@ const twoFactor = (options) => {
130
129
  value: user.id
131
130
  }]
132
131
  });
132
+ if (existingTwoFactor && existingTwoFactor.verified !== false) throw APIError.from("BAD_REQUEST", TWO_FACTOR_ERROR_CODES.TOTP_ALREADY_ENABLED);
133
+ const backupCodes = await generateBackupCodes(ctx.context.secretConfig, backupCodeOptions);
133
134
  const secret = generateRandomString(32);
134
135
  const encryptedSecret = await symmetricEncrypt({
135
136
  key: ctx.context.secretConfig,
@@ -146,7 +147,7 @@ const twoFactor = (options) => {
146
147
  const totpData = {
147
148
  secret: encryptedSecret,
148
149
  backupCodes: backupCodes.encryptedBackupCodes,
149
- verified: existingTwoFactor != null && existingTwoFactor.verified === true || !!options?.skipVerificationOnEnable
150
+ verified: !!options?.skipVerificationOnEnable
150
151
  };
151
152
  if (existingTwoFactor) await ctx.context.adapter.update({
152
153
  model: opts.twoFactorTable,
package/dist/state.d.mts CHANGED
@@ -9,26 +9,13 @@ declare const stateDataSchema: z.ZodObject<{
9
9
  errorURL: z.ZodOptional<z.ZodString>;
10
10
  newUserURL: z.ZodOptional<z.ZodString>;
11
11
  expiresAt: z.ZodNumber;
12
- /**
13
- * CSRF nonce returned to the OAuth provider. When using cookie state storage,
14
- * this must match the callback `state` query parameter.
15
- */
16
12
  oauthState: z.ZodOptional<z.ZodString>;
17
13
  link: z.ZodOptional<z.ZodObject<{
18
14
  email: z.ZodString;
19
15
  userId: z.ZodCoercedString<unknown>;
20
16
  }, z.core.$strip>>;
21
17
  requestSignUp: z.ZodOptional<z.ZodBoolean>;
22
- /**
23
- * OIDC nonce sent as the authorization request `nonce` parameter when the
24
- * provider requires an ID token to be bound to this redirect flow.
25
- */
26
18
  idTokenNonce: z.ZodOptional<z.ZodString>;
27
- /**
28
- * Server-controlled values that ride the state across the provider redirect.
29
- * Populated only by `generateState` from `addOAuthServerContext`, never from
30
- * the request body, so it is safe to trust on the callback.
31
- */
32
19
  serverContext: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
33
20
  }, z.core.$loose>;
34
21
  type StateData = z.infer<typeof stateDataSchema>;
@@ -90,7 +90,7 @@ async function getTestInstance(options, config) {
90
90
  advanced: { cookies: {} },
91
91
  logger: { level: "debug" }
92
92
  };
93
- const auth = betterAuth({
93
+ const authOptions = {
94
94
  baseURL: "http://localhost:" + (config?.port || 3e3),
95
95
  ...opts,
96
96
  ...options,
@@ -100,7 +100,15 @@ async function getTestInstance(options, config) {
100
100
  password: options?.emailAndPassword?.password ?? testPassword
101
101
  },
102
102
  plugins: [bearer(), ...options?.plugins || []]
103
- });
103
+ };
104
+ if (testWith !== "mongodb") {
105
+ const { runMigrations } = await getMigrations({
106
+ ...authOptions,
107
+ database: opts.database
108
+ });
109
+ await runMigrations();
110
+ }
111
+ const auth = betterAuth(authOptions);
104
112
  const testUser = {
105
113
  email: "test@test.com",
106
114
  password: "test123456",
@@ -117,13 +125,6 @@ async function getTestInstance(options, config) {
117
125
  headers
118
126
  });
119
127
  }
120
- if (testWith !== "mongodb") {
121
- const { runMigrations } = await getMigrations({
122
- ...auth.options,
123
- database: opts.database
124
- });
125
- await runMigrations();
126
- }
127
128
  await createTestUser();
128
129
  const cleanup = async () => {
129
130
  if (testWith === "mongodb") {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "better-auth",
3
- "version": "1.7.2",
3
+ "version": "1.7.3",
4
4
  "description": "The most comprehensive authentication framework for TypeScript.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -472,14 +472,14 @@
472
472
  "jose": "^6.2.3",
473
473
  "kysely": "^0.28.17 || ^0.29.0",
474
474
  "nanostores": "^1.3.0",
475
- "zod": "^4.3.6",
476
- "@better-auth/core": "1.7.2",
477
- "@better-auth/drizzle-adapter": "1.7.2",
478
- "@better-auth/kysely-adapter": "1.7.2",
479
- "@better-auth/memory-adapter": "1.7.2",
480
- "@better-auth/mongo-adapter": "1.7.2",
481
- "@better-auth/prisma-adapter": "1.7.2",
482
- "@better-auth/telemetry": "1.7.2"
475
+ "zod": "^4.5.4",
476
+ "@better-auth/core": "1.7.3",
477
+ "@better-auth/drizzle-adapter": "1.7.3",
478
+ "@better-auth/kysely-adapter": "1.7.3",
479
+ "@better-auth/memory-adapter": "1.7.3",
480
+ "@better-auth/mongo-adapter": "1.7.3",
481
+ "@better-auth/prisma-adapter": "1.7.3",
482
+ "@better-auth/telemetry": "1.7.3"
483
483
  },
484
484
  "devDependencies": {
485
485
  "@lynx-js/react": "^0.121.2",
@@ -1,5 +0,0 @@
1
- import "./url.mjs";
2
- import "../state.mjs";
3
- import "../oauth2/state.mjs";
4
- import "./hide-metadata.mjs";
5
- export {};