@better-auth/core 1.7.0-rc.5 → 1.7.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.
Files changed (117) hide show
  1. package/dist/api/index.d.mts +28 -28
  2. package/dist/async_hooks/index.d.mts +1 -0
  3. package/dist/async_hooks/pure.index.d.mts +1 -0
  4. package/dist/context/endpoint-context.d.mts +1 -1
  5. package/dist/context/endpoint-context.mjs +4 -4
  6. package/dist/context/global.d.mts +1 -0
  7. package/dist/context/global.mjs +1 -1
  8. package/dist/context/request-state.d.mts +1 -0
  9. package/dist/context/request-state.mjs +3 -6
  10. package/dist/context/transaction.d.mts +3 -4
  11. package/dist/context/transaction.mjs +4 -4
  12. package/dist/db/adapter/factory.d.mts +5 -3
  13. package/dist/db/adapter/factory.mjs +1 -1
  14. package/dist/db/adapter/get-default-field-name.d.mts +9 -2
  15. package/dist/db/adapter/get-default-model-name.d.mts +5 -1
  16. package/dist/db/adapter/get-field-attributes.d.mts +11 -4
  17. package/dist/db/adapter/get-field-name.d.mts +9 -2
  18. package/dist/db/adapter/get-id-field.d.mts +12 -4
  19. package/dist/db/adapter/get-model-name.d.mts +5 -1
  20. package/dist/db/adapter/index.d.mts +32 -7
  21. package/dist/db/adapter/types.d.mts +17 -5
  22. package/dist/db/adapter/utils.d.mts +1 -0
  23. package/dist/db/database-index.d.mts +12 -2
  24. package/dist/db/get-tables.d.mts +0 -1
  25. package/dist/db/plugin.d.mts +3 -3
  26. package/dist/db/schema/account.d.mts +1 -1
  27. package/dist/db/schema/rate-limit.d.mts +1 -1
  28. package/dist/db/schema/session.d.mts +1 -1
  29. package/dist/db/schema/shared.d.mts +1 -0
  30. package/dist/db/schema/user.d.mts +1 -1
  31. package/dist/db/schema/verification.d.mts +1 -1
  32. package/dist/db/type.d.mts +11 -8
  33. package/dist/env/logger.d.mts +25 -25
  34. package/dist/error/codes.d.mts +1 -0
  35. package/dist/error/index.d.mts +1 -0
  36. package/dist/index.d.mts +1 -1
  37. package/dist/instrumentation/attributes.d.mts +1 -0
  38. package/dist/instrumentation/pure.index.d.mts +1 -0
  39. package/dist/instrumentation/tracer.mjs +1 -1
  40. package/dist/oauth2/authorization-params.d.mts +1 -0
  41. package/dist/oauth2/client-assertion.d.mts +13 -3
  42. package/dist/oauth2/client-credentials-token.d.mts +17 -3
  43. package/dist/oauth2/create-authorization-url.d.mts +21 -3
  44. package/dist/oauth2/dpop.d.mts +23 -2
  45. package/dist/oauth2/dpop.mjs +1 -1
  46. package/dist/oauth2/oauth-provider.d.mts +7 -13
  47. package/dist/oauth2/refresh-access-token.d.mts +19 -3
  48. package/dist/oauth2/refresh-access-token.mjs +1 -1
  49. package/dist/oauth2/reject-redirects.mjs +1 -1
  50. package/dist/oauth2/token-endpoint-auth.d.mts +1 -0
  51. package/dist/oauth2/utils.d.mts +1 -0
  52. package/dist/oauth2/utils.mjs +1 -1
  53. package/dist/oauth2/validate-authorization-code.d.mts +29 -5
  54. package/dist/oauth2/verify-id-token.d.mts +1 -1
  55. package/dist/oauth2/verify.d.mts +7 -5
  56. package/dist/oauth2/verify.mjs +2 -2
  57. package/dist/social-providers/apple.d.mts +18 -5
  58. package/dist/social-providers/atlassian.d.mts +15 -4
  59. package/dist/social-providers/cognito.d.mts +18 -5
  60. package/dist/social-providers/discord.d.mts +13 -4
  61. package/dist/social-providers/dropbox.d.mts +15 -4
  62. package/dist/social-providers/facebook.d.mts +18 -6
  63. package/dist/social-providers/figma.d.mts +15 -4
  64. package/dist/social-providers/github.d.mts +16 -4
  65. package/dist/social-providers/gitlab.d.mts +16 -4
  66. package/dist/social-providers/google.d.mts +25 -6
  67. package/dist/social-providers/huggingface.d.mts +15 -4
  68. package/dist/social-providers/index.d.mts +504 -113
  69. package/dist/social-providers/kakao.d.mts +13 -4
  70. package/dist/social-providers/kick.d.mts +15 -4
  71. package/dist/social-providers/line.d.mts +16 -4
  72. package/dist/social-providers/linear.d.mts +14 -4
  73. package/dist/social-providers/linkedin.d.mts +14 -4
  74. package/dist/social-providers/microsoft-entra-id.d.mts +14 -5
  75. package/dist/social-providers/microsoft-entra-id.mjs +1 -2
  76. package/dist/social-providers/naver.d.mts +22 -23
  77. package/dist/social-providers/notion.d.mts +14 -4
  78. package/dist/social-providers/paybin.d.mts +16 -4
  79. package/dist/social-providers/paypal.d.mts +13 -4
  80. package/dist/social-providers/polar.d.mts +15 -4
  81. package/dist/social-providers/railway.d.mts +15 -4
  82. package/dist/social-providers/reddit.d.mts +13 -4
  83. package/dist/social-providers/roblox.d.mts +13 -4
  84. package/dist/social-providers/salesforce.d.mts +15 -4
  85. package/dist/social-providers/slack.d.mts +13 -4
  86. package/dist/social-providers/spotify.d.mts +15 -4
  87. package/dist/social-providers/tiktok.d.mts +14 -6
  88. package/dist/social-providers/twitch.d.mts +13 -4
  89. package/dist/social-providers/twitter.d.mts +19 -26
  90. package/dist/social-providers/vercel.d.mts +15 -4
  91. package/dist/social-providers/vk.d.mts +16 -4
  92. package/dist/social-providers/wechat.d.mts +12 -4
  93. package/dist/social-providers/zoom.d.mts +18 -6
  94. package/dist/types/context.d.mts +2 -2
  95. package/dist/types/cookie.d.mts +1 -1
  96. package/dist/types/helper.d.mts +1 -1
  97. package/dist/types/index.d.mts +1 -1
  98. package/dist/types/init-options.d.mts +18 -26
  99. package/dist/types/plugin-client.d.mts +3 -1
  100. package/dist/types/plugin.d.mts +2 -2
  101. package/dist/utils/async.d.mts +1 -0
  102. package/dist/utils/db.d.mts +0 -1
  103. package/dist/utils/deprecate.d.mts +1 -0
  104. package/dist/utils/email.d.mts +4 -1
  105. package/dist/utils/error-codes.d.mts +2 -2
  106. package/dist/utils/host.d.mts +1 -27
  107. package/dist/utils/host.mjs +1 -1
  108. package/dist/utils/ip.d.mts +0 -1
  109. package/dist/utils/ip.mjs +1 -1
  110. package/dist/utils/is-api-error.d.mts +1 -0
  111. package/dist/utils/redirect-uri.d.mts +1 -0
  112. package/package.json +2 -2
  113. package/src/context/endpoint-context.ts +6 -4
  114. package/src/context/request-state.ts +5 -23
  115. package/src/context/transaction.ts +6 -4
  116. package/src/db/type.ts +2 -1
  117. package/src/types/init-options.ts +6 -4
@@ -26,33 +26,7 @@
26
26
  * The semantic kind of a host, derived from RFC 6890 special-purpose registries
27
27
  * plus a few domain-name categories (localhost, cloud metadata FQDNs).
28
28
  */
29
- type HostKind =
30
- /** IPv4 `127.0.0.0/8` or IPv6 `::1`. */
31
- "loopback" |
32
- /** DNS name `localhost` or RFC 6761 `.localhost` TLD. */
33
- "localhost" |
34
- /** IPv4 `0.0.0.0` or IPv6 `::` — "this host on this network", not loopback. */
35
- "unspecified" |
36
- /** RFC 1918 `10/8`, `172.16/12`, `192.168/16`, or IPv6 ULA `fc00::/7`. */
37
- "private" |
38
- /** IPv4 `169.254/16` or IPv6 `fe80::/10`. Includes AWS IMDS `169.254.169.254`. */
39
- "linkLocal" |
40
- /** RFC 6598 carrier-grade NAT `100.64.0.0/10`. */
41
- "sharedAddressSpace" |
42
- /** RFC 5737 `192.0.2/24`, `198.51.100/24`, `203.0.113/24`, or RFC 3849 `2001:db8::/32`. */
43
- "documentation" |
44
- /** RFC 2544 `198.18.0.0/15`. */
45
- "benchmarking" |
46
- /** IPv4 `224.0.0.0/4` or IPv6 `ff00::/8`. */
47
- "multicast" |
48
- /** IPv4 limited broadcast `255.255.255.255`. */
49
- "broadcast" |
50
- /** Other RFC 6890 special-purpose ranges (0.0.0.0/8, 192.0.0.0/24, 192.88.99.0/24, 240.0.0.0/4, 2001::/32, etc.). */
51
- "reserved" |
52
- /** Cloud metadata service FQDN (e.g. `metadata.google.internal`). */
53
- "cloudMetadata" |
54
- /** Any host not matching a special-purpose range above. */
55
- "public";
29
+ type HostKind = /** IPv4 `127.0.0.0/8` or IPv6 `::1`. */"loopback" /** DNS name `localhost` or RFC 6761 `.localhost` TLD. */ | "localhost" /** IPv4 `0.0.0.0` or IPv6 `::` — "this host on this network", not loopback. */ | "unspecified" /** RFC 1918 `10/8`, `172.16/12`, `192.168/16`, or IPv6 ULA `fc00::/7`. */ | "private" /** IPv4 `169.254/16` or IPv6 `fe80::/10`. Includes AWS IMDS `169.254.169.254`. */ | "linkLocal" /** RFC 6598 carrier-grade NAT `100.64.0.0/10`. */ | "sharedAddressSpace" /** RFC 5737 `192.0.2/24`, `198.51.100/24`, `203.0.113/24`, or RFC 3849 `2001:db8::/32`. */ | "documentation" /** RFC 2544 `198.18.0.0/15`. */ | "benchmarking" /** IPv4 `224.0.0.0/4` or IPv6 `ff00::/8`. */ | "multicast" /** IPv4 limited broadcast `255.255.255.255`. */ | "broadcast" /** Other RFC 6890 special-purpose ranges (0.0.0.0/8, 192.0.0.0/24, 192.88.99.0/24, 240.0.0.0/4, 2001::/32, etc.). */ | "reserved" /** Cloud metadata service FQDN (e.g. `metadata.google.internal`). */ | "cloudMetadata" /** Any host not matching a special-purpose range above. */ | "public";
56
30
  /**
57
31
  * The syntactic form of the input host: an IPv4 literal, an IPv6 literal, or
58
32
  * a domain name. IPv4-mapped IPv6 (`::ffff:192.0.2.1`) is reported as `ipv4`
@@ -9,7 +9,7 @@ import { isValidIP, normalizeIP } from "./ip.mjs";
9
9
  * only exists for the FQDN form that a naive server-side fetch might resolve
10
10
  * via its own resolver.
11
11
  */
12
- const CLOUD_METADATA_HOSTS = /* @__PURE__ */ new Set([
12
+ const CLOUD_METADATA_HOSTS = new Set([
13
13
  "metadata.google.internal",
14
14
  "metadata.goog",
15
15
  "metadata",
@@ -1,5 +1,4 @@
1
1
  import { BetterAuthOptions } from "../types/init-options.mjs";
2
- import "../types/index.mjs";
3
2
  //#region src/utils/ip.d.ts
4
3
  /**
5
4
  * Normalizes an IP address for consistent rate limiting.
package/dist/utils/ip.mjs CHANGED
@@ -111,7 +111,7 @@ function ipToBytes(ip) {
111
111
  const mapped = extractIPv4FromMapped(ip);
112
112
  if (mapped) return Uint8Array.from(mapped.split(".").map((octet) => Number(octet)));
113
113
  const groups = expandIPv6(ip);
114
- const bytes = /* @__PURE__ */ new Uint8Array(16);
114
+ const bytes = new Uint8Array(16);
115
115
  for (let i = 0; i < 8; i++) {
116
116
  const group = Number.parseInt(groups[i] ?? "0", 16);
117
117
  bytes[i * 2] = group >> 8 & 255;
@@ -1,4 +1,5 @@
1
1
  import { APIError } from "../error/index.mjs";
2
+
2
3
  //#region src/utils/is-api-error.d.ts
3
4
  declare function isAPIError(error: unknown): error is APIError;
4
5
  //#endregion
@@ -1,4 +1,5 @@
1
1
  import * as z from "zod";
2
+
2
3
  //#region src/utils/redirect-uri.d.ts
3
4
  /**
4
5
  * Returns whether a parsed redirect URI uses an authority-free, reverse-domain
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@better-auth/core",
3
- "version": "1.7.0-rc.5",
3
+ "version": "1.7.0",
4
4
  "description": "The most comprehensive authentication framework for TypeScript.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -170,7 +170,7 @@
170
170
  "jose": "^6.2.3",
171
171
  "kysely": "^0.28.17 || ^0.29.0",
172
172
  "nanostores": "^1.3.0",
173
- "tsdown": "0.22.7"
173
+ "tsdown": "0.21.10"
174
174
  },
175
175
  "peerDependencies": {
176
176
  "@better-auth/utils": "0.4.2",
@@ -12,11 +12,13 @@ export type AuthEndpointContext = Partial<
12
12
 
13
13
  const ensureAsyncStorage = async () => {
14
14
  const betterAuthGlobal = __getBetterAuthGlobal();
15
- if (!betterAuthGlobal.context.endpointContextAsyncStorage) {
16
- const AsyncLocalStorage = await getAsyncLocalStorage();
17
- betterAuthGlobal.context.endpointContextAsyncStorage =
18
- new AsyncLocalStorage<AuthEndpointContext>();
15
+ const existing = betterAuthGlobal.context.endpointContextAsyncStorage;
16
+ if (existing) {
17
+ return existing as AsyncLocalStorage<AuthEndpointContext>;
19
18
  }
19
+ const AsyncLocalStorage = await getAsyncLocalStorage();
20
+ betterAuthGlobal.context.endpointContextAsyncStorage ??=
21
+ new AsyncLocalStorage<AuthEndpointContext>();
20
22
  return betterAuthGlobal.context
21
23
  .endpointContextAsyncStorage as AsyncLocalStorage<AuthEndpointContext>;
22
24
  };
@@ -4,35 +4,17 @@ import { __getBetterAuthGlobal } from "./global";
4
4
 
5
5
  export type RequestStateWeakMap = WeakMap<object, any>;
6
6
 
7
- // Memoizes the in-flight AsyncLocalStorage initialization so concurrent
8
- // first-callers share a single instance instead of each constructing one.
9
- let asyncStorageInit: Promise<AsyncLocalStorage<RequestStateWeakMap>> | null =
10
- null;
11
-
12
7
  const ensureAsyncStorage = async () => {
13
8
  const betterAuthGlobal = __getBetterAuthGlobal();
14
9
  const existing = betterAuthGlobal.context.requestStateAsyncStorage;
15
10
  if (existing) {
16
11
  return existing as AsyncLocalStorage<RequestStateWeakMap>;
17
12
  }
18
- // Without memoizing the init, several concurrent callers can each pass the
19
- // check above, each `await getAsyncLocalStorage()`, and each assign a fresh
20
- // instance — last write wins. `runWithRequestState().run()` then executes on
21
- // one instance while a nested `getCurrentRequestState()` reads the
22
- // overwritten one, throwing "No request state found". This shows up
23
- // intermittently on serverless cold start (e.g. Cloudflare Workers), where
24
- // the first requests hit before the lazy `node:async_hooks` import settles.
25
- // The idempotent `??=` keeps the global singleton stable even if multiple
26
- // BetterAuth copies (Dual Module Hazard) race here.
27
- if (!asyncStorageInit) {
28
- asyncStorageInit = getAsyncLocalStorage().then((AsyncLocalStorage) => {
29
- betterAuthGlobal.context.requestStateAsyncStorage ??=
30
- new AsyncLocalStorage<RequestStateWeakMap>();
31
- return betterAuthGlobal.context
32
- .requestStateAsyncStorage as AsyncLocalStorage<RequestStateWeakMap>;
33
- });
34
- }
35
- return asyncStorageInit;
13
+ const AsyncLocalStorage = await getAsyncLocalStorage();
14
+ betterAuthGlobal.context.requestStateAsyncStorage ??=
15
+ new AsyncLocalStorage<RequestStateWeakMap>();
16
+ return betterAuthGlobal.context
17
+ .requestStateAsyncStorage as AsyncLocalStorage<RequestStateWeakMap>;
36
18
  };
37
19
 
38
20
  export async function getRequestStateAsyncLocalStorage() {
@@ -1,4 +1,4 @@
1
- import type { AsyncLocalStorage } from "node:async_hooks";
1
+ import type { AsyncLocalStorage } from "@better-auth/core/async_hooks";
2
2
  import { getAsyncLocalStorage } from "@better-auth/core/async_hooks";
3
3
  import type { DBAdapter, DBTransactionAdapter } from "../db/adapter";
4
4
  import type { BetterAuthOptions } from "../types";
@@ -14,10 +14,12 @@ type HookContext = {
14
14
 
15
15
  const ensureAsyncStorage = async () => {
16
16
  const betterAuthGlobal = __getBetterAuthGlobal();
17
- if (!betterAuthGlobal.context.adapterAsyncStorage) {
18
- const AsyncLocalStorage = await getAsyncLocalStorage();
19
- betterAuthGlobal.context.adapterAsyncStorage = new AsyncLocalStorage();
17
+ const existing = betterAuthGlobal.context.adapterAsyncStorage;
18
+ if (existing) {
19
+ return existing as AsyncLocalStorage<HookContext>;
20
20
  }
21
+ const AsyncLocalStorage = await getAsyncLocalStorage();
22
+ betterAuthGlobal.context.adapterAsyncStorage ??= new AsyncLocalStorage();
21
23
  return betterAuthGlobal.context
22
24
  .adapterAsyncStorage as AsyncLocalStorage<HookContext>;
23
25
  };
package/src/db/type.ts CHANGED
@@ -251,7 +251,8 @@ export type DBFieldAttributeConfig = {
251
251
  */
252
252
  bigint?: boolean | undefined;
253
253
  /**
254
- * A zod schema to validate the value.
254
+ * A Standard Schema to validate the value. Works with any Standard Schema
255
+ * library, such as Zod, Valibot or ArkType.
255
256
  */
256
257
  validator?:
257
258
  | {
@@ -146,7 +146,8 @@ export type DynamicBaseURLConfig = {
146
146
  /**
147
147
  * List of allowed hostnames. Supports wildcard patterns.
148
148
  *
149
- * The derived host from the request will be validated against this list.
149
+ * `x-forwarded-host` is used only when `advanced.trustedProxyHeaders` is
150
+ * enabled.
150
151
  * Uses the same wildcard matching as `trustedOrigins`.
151
152
  *
152
153
  * @example
@@ -161,8 +162,9 @@ export type DynamicBaseURLConfig = {
161
162
  allowedHosts: string[];
162
163
 
163
164
  /**
164
- * Fallback URL to use if the derived host doesn't match any allowed host.
165
- * If not set, Better Auth will throw an error when the host doesn't match.
165
+ * Fallback URL used when no allowed request host can be resolved.
166
+ * If omitted, Better Auth throws when the request host is unavailable or not
167
+ * allowed.
166
168
  *
167
169
  * @example "https://myapp.com"
168
170
  */
@@ -172,7 +174,7 @@ export type DynamicBaseURLConfig = {
172
174
  * Protocol to use when constructing the URL.
173
175
  * - `"https"`: Always use HTTPS (recommended for production)
174
176
  * - `"http"`: Always use HTTP (for local development)
175
- * - `"auto"`: Derive from `x-forwarded-proto` header or default to HTTPS
177
+ * - `"auto"`: Trust `x-forwarded-proto` only when proxy headers are enabled
176
178
  *
177
179
  * @default "auto"
178
180
  */