@better-auth/core 1.7.0-rc.6 → 1.7.1
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/context/endpoint-context.mjs +4 -4
- package/dist/context/global.mjs +1 -1
- package/dist/context/request-state.mjs +3 -6
- package/dist/context/transaction.d.mts +1 -1
- package/dist/context/transaction.mjs +4 -4
- package/dist/instrumentation/tracer.mjs +1 -1
- package/package.json +1 -1
- package/src/context/endpoint-context.ts +6 -4
- package/src/context/request-state.ts +5 -23
- package/src/context/transaction.ts +6 -4
|
@@ -3,10 +3,10 @@ import { getAsyncLocalStorage } from "@better-auth/core/async_hooks";
|
|
|
3
3
|
//#region src/context/endpoint-context.ts
|
|
4
4
|
const ensureAsyncStorage = async () => {
|
|
5
5
|
const betterAuthGlobal = __getBetterAuthGlobal();
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
const existing = betterAuthGlobal.context.endpointContextAsyncStorage;
|
|
7
|
+
if (existing) return existing;
|
|
8
|
+
const AsyncLocalStorage = await getAsyncLocalStorage();
|
|
9
|
+
betterAuthGlobal.context.endpointContextAsyncStorage ??= new AsyncLocalStorage();
|
|
10
10
|
return betterAuthGlobal.context.endpointContextAsyncStorage;
|
|
11
11
|
};
|
|
12
12
|
/**
|
package/dist/context/global.mjs
CHANGED
|
@@ -1,16 +1,13 @@
|
|
|
1
1
|
import { __getBetterAuthGlobal } from "./global.mjs";
|
|
2
2
|
import { getAsyncLocalStorage } from "@better-auth/core/async_hooks";
|
|
3
3
|
//#region src/context/request-state.ts
|
|
4
|
-
let asyncStorageInit = null;
|
|
5
4
|
const ensureAsyncStorage = async () => {
|
|
6
5
|
const betterAuthGlobal = __getBetterAuthGlobal();
|
|
7
6
|
const existing = betterAuthGlobal.context.requestStateAsyncStorage;
|
|
8
7
|
if (existing) return existing;
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
});
|
|
13
|
-
return asyncStorageInit;
|
|
8
|
+
const AsyncLocalStorage = await getAsyncLocalStorage();
|
|
9
|
+
betterAuthGlobal.context.requestStateAsyncStorage ??= new AsyncLocalStorage();
|
|
10
|
+
return betterAuthGlobal.context.requestStateAsyncStorage;
|
|
14
11
|
};
|
|
15
12
|
async function getRequestStateAsyncLocalStorage() {
|
|
16
13
|
return ensureAsyncStorage();
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { DBAdapter, DBTransactionAdapter } from "../db/adapter/index.mjs";
|
|
2
2
|
import { BetterAuthOptions } from "../types/init-options.mjs";
|
|
3
|
-
import { AsyncLocalStorage } from "
|
|
3
|
+
import { AsyncLocalStorage } from "@better-auth/core/async_hooks";
|
|
4
4
|
|
|
5
5
|
//#region src/context/transaction.d.ts
|
|
6
6
|
type StoredAdapter = DBTransactionAdapter<BetterAuthOptions>;
|
|
@@ -3,10 +3,10 @@ import { getAsyncLocalStorage } from "@better-auth/core/async_hooks";
|
|
|
3
3
|
//#region src/context/transaction.ts
|
|
4
4
|
const ensureAsyncStorage = async () => {
|
|
5
5
|
const betterAuthGlobal = __getBetterAuthGlobal();
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
const existing = betterAuthGlobal.context.adapterAsyncStorage;
|
|
7
|
+
if (existing) return existing;
|
|
8
|
+
const AsyncLocalStorage = await getAsyncLocalStorage();
|
|
9
|
+
betterAuthGlobal.context.adapterAsyncStorage ??= new AsyncLocalStorage();
|
|
10
10
|
return betterAuthGlobal.context.adapterAsyncStorage;
|
|
11
11
|
};
|
|
12
12
|
/**
|
|
@@ -2,7 +2,7 @@ import { ATTR_HTTP_RESPONSE_STATUS_CODE } from "./attributes.mjs";
|
|
|
2
2
|
import { getOpenTelemetryAPI } from "./api.mjs";
|
|
3
3
|
//#region src/instrumentation/tracer.ts
|
|
4
4
|
const INSTRUMENTATION_SCOPE = "better-auth";
|
|
5
|
-
const INSTRUMENTATION_VERSION = "1.7.
|
|
5
|
+
const INSTRUMENTATION_VERSION = "1.7.1";
|
|
6
6
|
/**
|
|
7
7
|
* Better-auth uses `throw ctx.redirect(url)` for flow control (e.g. OAuth
|
|
8
8
|
* callbacks). These are APIErrors with 3xx status codes and should not be
|
package/package.json
CHANGED
|
@@ -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
|
};
|