@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.
- package/dist/api/index.d.mts +28 -28
- package/dist/async_hooks/index.d.mts +1 -0
- package/dist/async_hooks/pure.index.d.mts +1 -0
- package/dist/context/endpoint-context.d.mts +1 -1
- package/dist/context/endpoint-context.mjs +4 -4
- package/dist/context/global.d.mts +1 -0
- package/dist/context/global.mjs +1 -1
- package/dist/context/request-state.d.mts +1 -0
- package/dist/context/request-state.mjs +3 -6
- package/dist/context/transaction.d.mts +3 -4
- package/dist/context/transaction.mjs +4 -4
- package/dist/db/adapter/factory.d.mts +5 -3
- package/dist/db/adapter/factory.mjs +1 -1
- package/dist/db/adapter/get-default-field-name.d.mts +9 -2
- package/dist/db/adapter/get-default-model-name.d.mts +5 -1
- package/dist/db/adapter/get-field-attributes.d.mts +11 -4
- package/dist/db/adapter/get-field-name.d.mts +9 -2
- package/dist/db/adapter/get-id-field.d.mts +12 -4
- package/dist/db/adapter/get-model-name.d.mts +5 -1
- package/dist/db/adapter/index.d.mts +32 -7
- package/dist/db/adapter/types.d.mts +17 -5
- package/dist/db/adapter/utils.d.mts +1 -0
- package/dist/db/database-index.d.mts +12 -2
- package/dist/db/get-tables.d.mts +0 -1
- package/dist/db/plugin.d.mts +3 -3
- package/dist/db/schema/account.d.mts +1 -1
- package/dist/db/schema/rate-limit.d.mts +1 -1
- package/dist/db/schema/session.d.mts +1 -1
- package/dist/db/schema/shared.d.mts +1 -0
- package/dist/db/schema/user.d.mts +1 -1
- package/dist/db/schema/verification.d.mts +1 -1
- package/dist/db/type.d.mts +11 -8
- package/dist/env/logger.d.mts +25 -25
- package/dist/error/codes.d.mts +1 -0
- package/dist/error/index.d.mts +1 -0
- package/dist/index.d.mts +1 -1
- package/dist/instrumentation/attributes.d.mts +1 -0
- package/dist/instrumentation/pure.index.d.mts +1 -0
- package/dist/instrumentation/tracer.mjs +1 -1
- package/dist/oauth2/authorization-params.d.mts +1 -0
- package/dist/oauth2/client-assertion.d.mts +13 -3
- package/dist/oauth2/client-credentials-token.d.mts +17 -3
- package/dist/oauth2/create-authorization-url.d.mts +21 -3
- package/dist/oauth2/dpop.d.mts +23 -2
- package/dist/oauth2/dpop.mjs +1 -1
- package/dist/oauth2/oauth-provider.d.mts +7 -13
- package/dist/oauth2/refresh-access-token.d.mts +19 -3
- package/dist/oauth2/refresh-access-token.mjs +1 -1
- package/dist/oauth2/reject-redirects.mjs +1 -1
- package/dist/oauth2/token-endpoint-auth.d.mts +1 -0
- package/dist/oauth2/utils.d.mts +1 -0
- package/dist/oauth2/utils.mjs +1 -1
- package/dist/oauth2/validate-authorization-code.d.mts +29 -5
- package/dist/oauth2/verify-id-token.d.mts +1 -1
- package/dist/oauth2/verify.d.mts +7 -5
- package/dist/oauth2/verify.mjs +2 -2
- package/dist/social-providers/apple.d.mts +18 -5
- package/dist/social-providers/atlassian.d.mts +15 -4
- package/dist/social-providers/cognito.d.mts +18 -5
- package/dist/social-providers/discord.d.mts +13 -4
- package/dist/social-providers/dropbox.d.mts +15 -4
- package/dist/social-providers/facebook.d.mts +18 -6
- package/dist/social-providers/figma.d.mts +15 -4
- package/dist/social-providers/github.d.mts +16 -4
- package/dist/social-providers/gitlab.d.mts +16 -4
- package/dist/social-providers/google.d.mts +25 -6
- package/dist/social-providers/huggingface.d.mts +15 -4
- package/dist/social-providers/index.d.mts +504 -113
- package/dist/social-providers/kakao.d.mts +13 -4
- package/dist/social-providers/kick.d.mts +15 -4
- package/dist/social-providers/line.d.mts +16 -4
- package/dist/social-providers/linear.d.mts +14 -4
- package/dist/social-providers/linkedin.d.mts +14 -4
- package/dist/social-providers/microsoft-entra-id.d.mts +14 -5
- package/dist/social-providers/microsoft-entra-id.mjs +1 -2
- package/dist/social-providers/naver.d.mts +22 -23
- package/dist/social-providers/notion.d.mts +14 -4
- package/dist/social-providers/paybin.d.mts +16 -4
- package/dist/social-providers/paypal.d.mts +13 -4
- package/dist/social-providers/polar.d.mts +15 -4
- package/dist/social-providers/railway.d.mts +15 -4
- package/dist/social-providers/reddit.d.mts +13 -4
- package/dist/social-providers/roblox.d.mts +13 -4
- package/dist/social-providers/salesforce.d.mts +15 -4
- package/dist/social-providers/slack.d.mts +13 -4
- package/dist/social-providers/spotify.d.mts +15 -4
- package/dist/social-providers/tiktok.d.mts +14 -6
- package/dist/social-providers/twitch.d.mts +13 -4
- package/dist/social-providers/twitter.d.mts +19 -26
- package/dist/social-providers/vercel.d.mts +15 -4
- package/dist/social-providers/vk.d.mts +16 -4
- package/dist/social-providers/wechat.d.mts +12 -4
- package/dist/social-providers/zoom.d.mts +18 -6
- package/dist/types/context.d.mts +2 -2
- package/dist/types/cookie.d.mts +1 -1
- package/dist/types/helper.d.mts +1 -1
- package/dist/types/index.d.mts +1 -1
- package/dist/types/init-options.d.mts +18 -26
- package/dist/types/plugin-client.d.mts +3 -1
- package/dist/types/plugin.d.mts +2 -2
- package/dist/utils/async.d.mts +1 -0
- package/dist/utils/db.d.mts +0 -1
- package/dist/utils/deprecate.d.mts +1 -0
- package/dist/utils/email.d.mts +4 -1
- package/dist/utils/error-codes.d.mts +2 -2
- package/dist/utils/host.d.mts +1 -27
- package/dist/utils/host.mjs +1 -1
- package/dist/utils/ip.d.mts +0 -1
- package/dist/utils/ip.mjs +1 -1
- package/dist/utils/is-api-error.d.mts +1 -0
- package/dist/utils/redirect-uri.d.mts +1 -0
- package/package.json +2 -2
- package/src/context/endpoint-context.ts +6 -4
- package/src/context/request-state.ts +5 -23
- package/src/context/transaction.ts +6 -4
- package/src/db/type.ts +2 -1
- package/src/types/init-options.ts +6 -4
package/dist/utils/host.d.mts
CHANGED
|
@@ -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`
|
package/dist/utils/host.mjs
CHANGED
|
@@ -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 =
|
|
12
|
+
const CLOUD_METADATA_HOSTS = new Set([
|
|
13
13
|
"metadata.google.internal",
|
|
14
14
|
"metadata.goog",
|
|
15
15
|
"metadata",
|
package/dist/utils/ip.d.mts
CHANGED
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 =
|
|
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;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@better-auth/core",
|
|
3
|
-
"version": "1.7.0
|
|
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.
|
|
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
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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 "
|
|
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
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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
|
|
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
|
-
*
|
|
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
|
|
165
|
-
* If
|
|
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"`:
|
|
177
|
+
* - `"auto"`: Trust `x-forwarded-proto` only when proxy headers are enabled
|
|
176
178
|
*
|
|
177
179
|
* @default "auto"
|
|
178
180
|
*/
|