@better-auth/core 1.4.6 → 1.4.7-beta.2

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 (42) hide show
  1. package/.turbo/turbo-build.log +22 -22
  2. package/dist/api/index.d.mts +1 -1
  3. package/dist/api/index.mjs +1 -3
  4. package/dist/async_hooks/index.d.mts +6 -2
  5. package/dist/async_hooks/index.mjs +19 -2
  6. package/dist/{index-Da4Ujjef.d.mts → async_hooks/pure.index.d.mts} +2 -2
  7. package/dist/async_hooks/pure.index.mjs +34 -0
  8. package/dist/context/index.d.mts +2 -2
  9. package/dist/context/index.mjs +1 -3
  10. package/dist/{context-su4uu82y.mjs → context-DblZrIwO.mjs} +1 -1
  11. package/dist/db/adapter/index.d.mts +1 -1
  12. package/dist/db/adapter/index.mjs +4 -4
  13. package/dist/db/index.d.mts +1 -1
  14. package/dist/db/index.mjs +1 -1
  15. package/dist/env/index.d.mts +1 -1
  16. package/dist/env/index.mjs +1 -1
  17. package/dist/error/index.mjs +3 -3
  18. package/dist/{error-CMXuwPsa.mjs → error-CzMAIrPb.mjs} +1 -1
  19. package/dist/{index-D6KwwQy5.d.mts → index-CH_f5upI.d.mts} +3 -3
  20. package/dist/index.d.mts +1 -1
  21. package/dist/oauth2/index.d.mts +1 -1
  22. package/dist/oauth2/index.mjs +1 -1
  23. package/dist/social-providers/index.d.mts +1 -1
  24. package/dist/social-providers/index.mjs +5 -5
  25. package/dist/utils/index.mjs +2 -2
  26. package/dist/{utils-BqQC77zO.mjs → utils-NloIXYE0.mjs} +1 -1
  27. package/package.json +9 -2
  28. package/src/async_hooks/index.ts +0 -30
  29. package/src/async_hooks/pure.index.ts +46 -0
  30. package/src/context/endpoint-context.ts +2 -2
  31. package/src/context/request-state.ts +2 -2
  32. package/src/context/transaction.ts +2 -2
  33. package/src/db/adapter/index.ts +1 -1
  34. package/src/social-providers/facebook.ts +1 -1
  35. package/src/types/context.ts +1 -1
  36. package/tsdown.config.ts +2 -0
  37. package/dist/async_hooks-CrTStdt6.mjs +0 -45
  38. package/src/async_hooks/convex.spec.ts +0 -12
  39. /package/dist/{env-D6s-lvJz.mjs → env-DbssmzoK.mjs} +0 -0
  40. /package/dist/{get-tables-BGfrxIVZ.mjs → get-tables-DeuRhD_P.mjs} +0 -0
  41. /package/dist/{index-D4vfN5ui.d.mts → index-BRBu0-5h.d.mts} +0 -0
  42. /package/dist/{oauth2-7k48hhcV.mjs → oauth2-D2y9ALiO.mjs} +0 -0
@@ -1,43 +1,43 @@
1
1
 
2
- > @better-auth/core@1.4.6 build /home/runner/work/better-auth/better-auth/packages/core
2
+ > @better-auth/core@1.4.7-beta.2 build /home/runner/work/better-auth/better-auth/packages/core
3
3
  > tsdown
4
4
 
5
- ℹ tsdown v0.17.0 powered by rolldown v1.0.0-beta.53
5
+ ℹ tsdown v0.17.2 powered by rolldown v1.0.0-beta.53
6
6
  ℹ config file: /home/runner/work/better-auth/better-auth/packages/core/tsdown.config.ts
7
- ℹ entry: src/index.ts, src/db/index.ts, src/db/adapter/index.ts, src/async_hooks/index.ts, src/context/index.ts, src/env/index.ts, src/oauth2/index.ts, src/api/index.ts, src/social-providers/index.ts, src/utils/index.ts, src/error/index.ts
7
+ ℹ entry: src/index.ts, src/db/index.ts, src/db/adapter/index.ts, src/async_hooks/index.ts, src/async_hooks/pure.index.ts, src/context/index.ts, src/env/index.ts, src/oauth2/index.ts, src/api/index.ts, src/social-providers/index.ts, src/utils/index.ts, src/error/index.ts
8
8
  ℹ tsconfig: tsconfig.json
9
9
  ℹ Build start
10
- ℹ dist/social-providers/index.mjs  80.70 kB │ gzip: 10.32 kB
10
+ ℹ dist/social-providers/index.mjs  80.69 kB │ gzip: 10.32 kB
11
11
  ℹ dist/db/adapter/index.mjs  38.13 kB │ gzip: 7.79 kB
12
12
  ℹ dist/db/index.mjs  1.66 kB │ gzip: 0.54 kB
13
- ℹ dist/api/index.mjs  0.86 kB │ gzip: 0.42 kB
14
- ℹ dist/context/index.mjs  0.77 kB │ gzip: 0.28 kB
13
+ ℹ dist/async_hooks/index.mjs  1.03 kB │ gzip: 0.54 kB
14
+ ℹ dist/async_hooks/pure.index.mjs  0.99 kB │ gzip: 0.49 kB
15
+ ℹ dist/api/index.mjs  0.80 kB │ gzip: 0.38 kB
16
+ ℹ dist/context/index.mjs  0.70 kB │ gzip: 0.24 kB
15
17
  ℹ dist/oauth2/index.mjs  0.61 kB │ gzip: 0.24 kB
16
18
  ℹ dist/env/index.mjs  0.44 kB │ gzip: 0.25 kB
17
19
  ℹ dist/utils/index.mjs  0.24 kB │ gzip: 0.17 kB
18
20
  ℹ dist/error/index.mjs  0.19 kB │ gzip: 0.14 kB
19
- ℹ dist/async_hooks/index.mjs  0.14 kB │ gzip: 0.12 kB
20
21
  ℹ dist/index.mjs  0.01 kB │ gzip: 0.03 kB
21
- ℹ dist/oauth2-7k48hhcV.mjs  9.19 kB │ gzip: 2.13 kB
22
- ℹ dist/env-D6s-lvJz.mjs  7.67 kB │ gzip: 2.54 kB
23
- ℹ dist/get-tables-BGfrxIVZ.mjs  6.67 kB │ gzip: 1.29 kB
24
- ℹ dist/context-su4uu82y.mjs  3.89 kB │ gzip: 1.00 kB
25
- ℹ dist/error-CMXuwPsa.mjs  1.77 kB │ gzip: 0.79 kB
26
- ℹ dist/async_hooks-CrTStdt6.mjs  1.70 kB │ gzip: 0.85 kB
27
- ℹ dist/utils-BqQC77zO.mjs  1.10 kB │ gzip: 0.55 kB
22
+ ℹ dist/oauth2-D2y9ALiO.mjs  9.19 kB │ gzip: 2.13 kB
23
+ ℹ dist/env-DbssmzoK.mjs  7.67 kB │ gzip: 2.54 kB
24
+ ℹ dist/get-tables-DeuRhD_P.mjs  6.67 kB │ gzip: 1.29 kB
25
+ ℹ dist/context-DblZrIwO.mjs  3.89 kB │ gzip: 1.00 kB
26
+ ℹ dist/error-CzMAIrPb.mjs  1.77 kB │ gzip: 0.79 kB
27
+ ℹ dist/utils-NloIXYE0.mjs  1.10 kB │ gzip: 0.55 kB
28
28
  ℹ dist/social-providers/index.d.mts  3.88 kB │ gzip: 1.19 kB
29
- ℹ dist/context/index.d.mts  3.02 kB │ gzip: 0.95 kB
29
+ ℹ dist/context/index.d.mts  3.02 kB │ gzip: 0.96 kB
30
30
  ℹ dist/error/index.d.mts  1.84 kB │ gzip: 0.72 kB
31
- ℹ dist/db/adapter/index.d.mts  1.34 kB │ gzip: 0.43 kB
31
+ ℹ dist/db/adapter/index.d.mts  1.34 kB │ gzip: 0.42 kB
32
32
  ℹ dist/utils/index.d.mts  1.19 kB │ gzip: 0.55 kB
33
33
  ℹ dist/db/index.d.mts  1.04 kB │ gzip: 0.38 kB
34
34
  ℹ dist/index.d.mts  0.86 kB │ gzip: 0.33 kB
35
35
  ℹ dist/oauth2/index.d.mts  0.76 kB │ gzip: 0.29 kB
36
36
  ℹ dist/env/index.d.mts  0.59 kB │ gzip: 0.30 kB
37
37
  ℹ dist/api/index.d.mts  0.26 kB │ gzip: 0.14 kB
38
- ℹ dist/async_hooks/index.d.mts  0.14 kB │ gzip: 0.10 kB
39
- ℹ dist/index-D6KwwQy5.d.mts 218.31 kB │ gzip: 34.38 kB
40
- ℹ dist/index-D4vfN5ui.d.mts  3.31 kB │ gzip: 1.11 kB
41
- ℹ dist/index-Da4Ujjef.d.mts  0.24 kB │ gzip: 0.16 kB
42
- ℹ 32 files, total: 392.54 kB
43
- ✔ Build complete in 4673ms
38
+ ℹ dist/async_hooks/index.d.mts  0.24 kB │ gzip: 0.16 kB
39
+ ℹ dist/async_hooks/pure.index.d.mts  0.22 kB │ gzip: 0.16 kB
40
+ ℹ dist/index-CH_f5upI.d.mts 218.31 kB │ gzip: 34.38 kB
41
+ ℹ dist/index-BRBu0-5h.d.mts  3.31 kB │ gzip: 1.11 kB
42
+ ℹ 32 files, total: 392.66 kB
43
+ ✔ Build complete in 4837ms
@@ -1,2 +1,2 @@
1
- import { a as optionsMiddleware, i as createAuthMiddleware, n as AuthMiddleware, r as createAuthEndpoint, t as AuthEndpoint } from "../index-D6KwwQy5.mjs";
1
+ import { a as optionsMiddleware, i as createAuthMiddleware, n as AuthMiddleware, r as createAuthEndpoint, t as AuthEndpoint } from "../index-CH_f5upI.mjs";
2
2
  export { AuthEndpoint, AuthMiddleware, createAuthEndpoint, createAuthMiddleware, optionsMiddleware };
@@ -1,6 +1,4 @@
1
- import "../env-D6s-lvJz.mjs";
2
- import "../async_hooks-CrTStdt6.mjs";
3
- import { f as runWithEndpointContext } from "../context-su4uu82y.mjs";
1
+ import { f as runWithEndpointContext } from "../context-DblZrIwO.mjs";
4
2
  import { createEndpoint, createMiddleware } from "better-call";
5
3
 
6
4
  //#region src/api/index.ts
@@ -1,2 +1,6 @@
1
- import { n as getAsyncLocalStorage, t as AsyncLocalStorage } from "../index-Da4Ujjef.mjs";
2
- export { AsyncLocalStorage, getAsyncLocalStorage };
1
+ import { AsyncLocalStorage } from "node:async_hooks";
2
+
3
+ //#region src/async_hooks/index.d.ts
4
+ declare function getAsyncLocalStorage(): Promise<typeof AsyncLocalStorage>;
5
+ //#endregion
6
+ export { type AsyncLocalStorage, getAsyncLocalStorage };
@@ -1,4 +1,21 @@
1
- import "../env-D6s-lvJz.mjs";
2
- import { t as getAsyncLocalStorage } from "../async_hooks-CrTStdt6.mjs";
1
+ //#region src/async_hooks/index.ts
2
+ const AsyncLocalStoragePromise = import(
3
+ /* @vite-ignore */
4
+ /* webpackIgnore: true */
5
+ "node:async_hooks"
6
+ ).then((mod) => mod.AsyncLocalStorage).catch((err) => {
7
+ if ("AsyncLocalStorage" in globalThis) return globalThis.AsyncLocalStorage;
8
+ if (typeof window !== "undefined") return null;
9
+ console.warn("[better-auth] Warning: AsyncLocalStorage is not available in this environment. Some features may not work as expected.");
10
+ console.warn("[better-auth] Please read more about this warning at https://better-auth.com/docs/installation#mount-handler");
11
+ console.warn("[better-auth] If you are using Cloudflare Workers, please see: https://developers.cloudflare.com/workers/configuration/compatibility-flags/#nodejs-compatibility-flag");
12
+ throw err;
13
+ });
14
+ async function getAsyncLocalStorage() {
15
+ const mod = await AsyncLocalStoragePromise;
16
+ if (mod === null) throw new Error("getAsyncLocalStorage is only available in server code");
17
+ else return mod;
18
+ }
3
19
 
20
+ //#endregion
4
21
  export { getAsyncLocalStorage };
@@ -1,6 +1,6 @@
1
1
  import { AsyncLocalStorage } from "node:async_hooks";
2
2
 
3
- //#region src/async_hooks/index.d.ts
3
+ //#region src/async_hooks/pure.index.d.ts
4
4
  declare function getAsyncLocalStorage(): Promise<typeof AsyncLocalStorage>;
5
5
  //#endregion
6
- export { getAsyncLocalStorage as n, AsyncLocalStorage as t };
6
+ export { getAsyncLocalStorage };
@@ -0,0 +1,34 @@
1
+ //#region src/async_hooks/pure.index.ts
2
+ /**
3
+ * Due to the lack of AsyncLocalStorage in some environments (like Convex),
4
+ *
5
+ * We assume serverless functions are short-lived and single-threaded, so we can use a simple polyfill.
6
+ */
7
+ var AsyncLocalStoragePolyfill = class {
8
+ #current = void 0;
9
+ run(store, fn) {
10
+ const prev = this.#current;
11
+ this.#current = store;
12
+ const result = fn();
13
+ if (result instanceof Promise) return result.finally(() => {
14
+ this.#current = prev;
15
+ });
16
+ this.#current = prev;
17
+ return result;
18
+ }
19
+ getStore() {
20
+ return this.#current;
21
+ }
22
+ };
23
+ const AsyncLocalStoragePromise = Promise.resolve().then(() => {
24
+ if ("AsyncLocalStorage" in globalThis) return globalThis.AsyncLocalStorage;
25
+ return AsyncLocalStoragePolyfill;
26
+ });
27
+ async function getAsyncLocalStorage() {
28
+ const mod = await AsyncLocalStoragePromise;
29
+ if (mod === null) throw new Error("getAsyncLocalStorage is only available in server code");
30
+ else return mod;
31
+ }
32
+
33
+ //#endregion
34
+ export { getAsyncLocalStorage };
@@ -1,5 +1,5 @@
1
- import { Kn as DBAdapter, Zn as DBTransactionAdapter, f as AuthContext } from "../index-D6KwwQy5.mjs";
2
- import { t as AsyncLocalStorage } from "../index-Da4Ujjef.mjs";
1
+ import { Kn as DBAdapter, Zn as DBTransactionAdapter, f as AuthContext } from "../index-CH_f5upI.mjs";
2
+ import { AsyncLocalStorage } from "@better-auth/core/async_hooks";
3
3
  import { EndpointContext, InputContext } from "better-call";
4
4
 
5
5
  //#region src/context/endpoint-context.d.ts
@@ -1,5 +1,3 @@
1
- import "../env-D6s-lvJz.mjs";
2
- import "../async_hooks-CrTStdt6.mjs";
3
- import { a as defineRequestState, c as hasRequestState, d as getCurrentAuthContextAsyncLocalStorage, f as runWithEndpointContext, i as runWithTransaction, l as runWithRequestState, n as getCurrentDBAdapterAsyncLocalStorage, o as getCurrentRequestState, r as runWithAdapter, s as getRequestStateAsyncLocalStorage, t as getCurrentAdapter, u as getCurrentAuthContext } from "../context-su4uu82y.mjs";
1
+ import { a as defineRequestState, c as hasRequestState, d as getCurrentAuthContextAsyncLocalStorage, f as runWithEndpointContext, i as runWithTransaction, l as runWithRequestState, n as getCurrentDBAdapterAsyncLocalStorage, o as getCurrentRequestState, r as runWithAdapter, s as getRequestStateAsyncLocalStorage, t as getCurrentAdapter, u as getCurrentAuthContext } from "../context-DblZrIwO.mjs";
4
2
 
5
3
  export { defineRequestState, getCurrentAdapter, getCurrentAuthContext, getCurrentAuthContextAsyncLocalStorage, getCurrentDBAdapterAsyncLocalStorage, getCurrentRequestState, getRequestStateAsyncLocalStorage, hasRequestState, runWithAdapter, runWithEndpointContext, runWithRequestState, runWithTransaction };
@@ -1,4 +1,4 @@
1
- import { t as getAsyncLocalStorage } from "./async_hooks-CrTStdt6.mjs";
1
+ import { getAsyncLocalStorage } from "@better-auth/core/async_hooks";
2
2
 
3
3
  //#region src/context/endpoint-context.ts
4
4
  let currentContextAsyncStorage = null;
@@ -1,2 +1,2 @@
1
- import { $n as JoinOption, Gn as CustomAdapter, Jn as DBAdapterFactoryConfig, Kn as DBAdapter, Qn as JoinConfig, Wn as CleanedWhere, Xn as DBAdapterSchemaCreation, Yn as DBAdapterInstance, Zn as DBTransactionAdapter, _r as initGetIdField, ar as createAdapterFactory, br as initGetDefaultModelName, cr as AdapterFactoryCustomizeAdapterCreator, dr as CreateAdapterOptions, er as Where, fr as CreateCustomAdapter, gr as initGetModelName, ir as createAdapter, lr as AdapterFactoryOptions, nr as withApplyDefault, or as AdapterConfig, qn as DBAdapterDebugLogOption, rr as AdapterFactory, sr as AdapterFactoryConfig, tr as deepmerge, ur as AdapterTestDebugLogs, vr as initGetFieldName, xr as initGetDefaultFieldName, yr as initGetFieldAttributes } from "../../index-D6KwwQy5.mjs";
1
+ import { $n as JoinOption, Gn as CustomAdapter, Jn as DBAdapterFactoryConfig, Kn as DBAdapter, Qn as JoinConfig, Wn as CleanedWhere, Xn as DBAdapterSchemaCreation, Yn as DBAdapterInstance, Zn as DBTransactionAdapter, _r as initGetIdField, ar as createAdapterFactory, br as initGetDefaultModelName, cr as AdapterFactoryCustomizeAdapterCreator, dr as CreateAdapterOptions, er as Where, fr as CreateCustomAdapter, gr as initGetModelName, ir as createAdapter, lr as AdapterFactoryOptions, nr as withApplyDefault, or as AdapterConfig, qn as DBAdapterDebugLogOption, rr as AdapterFactory, sr as AdapterFactoryConfig, tr as deepmerge, ur as AdapterTestDebugLogs, vr as initGetFieldName, xr as initGetDefaultFieldName, yr as initGetFieldAttributes } from "../../index-CH_f5upI.mjs";
2
2
  export { AdapterConfig, AdapterFactory, AdapterFactoryConfig, AdapterFactoryCustomizeAdapterCreator, AdapterFactoryOptions, AdapterTestDebugLogs, CleanedWhere, CreateAdapterOptions, CreateCustomAdapter, CustomAdapter, DBAdapter, DBAdapterDebugLogOption, DBAdapterFactoryConfig, DBAdapterInstance, DBAdapterSchemaCreation, DBTransactionAdapter, JoinConfig, JoinOption, Where, createAdapter, createAdapterFactory, deepmerge, initGetDefaultFieldName, initGetDefaultModelName, initGetFieldAttributes, initGetFieldName, initGetIdField, initGetModelName, withApplyDefault };
@@ -1,7 +1,7 @@
1
- import { t as getAuthTables } from "../../get-tables-BGfrxIVZ.mjs";
2
- import { i as logger, n as createLogger, o as getColorDepth, t as TTY_COLORS } from "../../env-D6s-lvJz.mjs";
3
- import { n as safeJSONParse, r as generateId } from "../../utils-BqQC77zO.mjs";
4
- import { t as BetterAuthError } from "../../error-CMXuwPsa.mjs";
1
+ import { t as getAuthTables } from "../../get-tables-DeuRhD_P.mjs";
2
+ import { i as logger, n as createLogger, o as getColorDepth, t as TTY_COLORS } from "../../env-DbssmzoK.mjs";
3
+ import { n as safeJSONParse, r as generateId } from "../../utils-NloIXYE0.mjs";
4
+ import { t as BetterAuthError } from "../../error-CzMAIrPb.mjs";
5
5
 
6
6
  //#region src/db/adapter/get-default-model-name.ts
7
7
  const initGetDefaultModelName = ({ usePlural, schema }) => {
@@ -1,2 +1,2 @@
1
- import { Ar as verificationSchema, Br as BetterAuthPluginDBSchema, Cr as BetterAuthDbSchema, Dr as Primitive, Er as FieldType, Fr as sessionSchema, Gr as DBFieldType, Hr as BetterAuthDBSchema, Ir as RateLimit, Jr as SecondaryStorage, Kr as DBPrimitive, Lr as rateLimitSchema, Mr as userSchema, Nr as coreSchema, Or as getAuthTables, Pr as Session, Rr as Account, Sr as AuthPluginSchema, Tr as FieldAttributeConfig, Ur as DBFieldAttribute, Vr as BaseModelNames, Wr as DBFieldAttributeConfig, jr as User, kr as Verification, qr as ModelNames, wr as FieldAttribute, zr as accountSchema } from "../index-D6KwwQy5.mjs";
1
+ import { Ar as verificationSchema, Br as BetterAuthPluginDBSchema, Cr as BetterAuthDbSchema, Dr as Primitive, Er as FieldType, Fr as sessionSchema, Gr as DBFieldType, Hr as BetterAuthDBSchema, Ir as RateLimit, Jr as SecondaryStorage, Kr as DBPrimitive, Lr as rateLimitSchema, Mr as userSchema, Nr as coreSchema, Or as getAuthTables, Pr as Session, Rr as Account, Sr as AuthPluginSchema, Tr as FieldAttributeConfig, Ur as DBFieldAttribute, Vr as BaseModelNames, Wr as DBFieldAttributeConfig, jr as User, kr as Verification, qr as ModelNames, wr as FieldAttribute, zr as accountSchema } from "../index-CH_f5upI.mjs";
2
2
  export { Account, AuthPluginSchema, BaseModelNames, BetterAuthDBSchema, BetterAuthDbSchema, BetterAuthPluginDBSchema, DBFieldAttribute, DBFieldAttributeConfig, DBFieldType, DBPrimitive, FieldAttribute, FieldAttributeConfig, FieldType, ModelNames, Primitive, RateLimit, SecondaryStorage, Session, User, Verification, accountSchema, coreSchema, getAuthTables, rateLimitSchema, sessionSchema, userSchema, verificationSchema };
package/dist/db/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { t as getAuthTables } from "../get-tables-BGfrxIVZ.mjs";
1
+ import { t as getAuthTables } from "../get-tables-DeuRhD_P.mjs";
2
2
  import * as z from "zod";
3
3
 
4
4
  //#region src/db/schema/shared.ts
@@ -1,2 +1,2 @@
1
- import { _ as isTest, a as TTY_COLORS, c as logger, d as EnvObject, f as env, g as isProduction, h as isDevelopment, i as Logger, l as shouldPublishLog, m as getEnvVar, n as LogHandlerParams, o as createLogger, p as getBooleanEnvVar, r as LogLevel, s as levels, t as InternalLogger, u as ENV, v as nodeENV, y as getColorDepth } from "../index-D4vfN5ui.mjs";
1
+ import { _ as isTest, a as TTY_COLORS, c as logger, d as EnvObject, f as env, g as isProduction, h as isDevelopment, i as Logger, l as shouldPublishLog, m as getEnvVar, n as LogHandlerParams, o as createLogger, p as getBooleanEnvVar, r as LogLevel, s as levels, t as InternalLogger, u as ENV, v as nodeENV, y as getColorDepth } from "../index-BRBu0-5h.mjs";
2
2
  export { ENV, EnvObject, InternalLogger, LogHandlerParams, LogLevel, Logger, TTY_COLORS, createLogger, env, getBooleanEnvVar, getColorDepth, getEnvVar, isDevelopment, isProduction, isTest, levels, logger, nodeENV, shouldPublishLog };
@@ -1,3 +1,3 @@
1
- import { a as shouldPublishLog, c as env, d as isDevelopment, f as isProduction, i as logger, l as getBooleanEnvVar, m as nodeENV, n as createLogger, o as getColorDepth, p as isTest, r as levels, s as ENV, t as TTY_COLORS, u as getEnvVar } from "../env-D6s-lvJz.mjs";
1
+ import { a as shouldPublishLog, c as env, d as isDevelopment, f as isProduction, i as logger, l as getBooleanEnvVar, m as nodeENV, n as createLogger, o as getColorDepth, p as isTest, r as levels, s as ENV, t as TTY_COLORS, u as getEnvVar } from "../env-DbssmzoK.mjs";
2
2
 
3
3
  export { ENV, TTY_COLORS, createLogger, env, getBooleanEnvVar, getColorDepth, getEnvVar, isDevelopment, isProduction, isTest, levels, logger, nodeENV, shouldPublishLog };
@@ -1,5 +1,5 @@
1
- import "../env-D6s-lvJz.mjs";
2
- import "../utils-BqQC77zO.mjs";
3
- import { n as BASE_ERROR_CODES, t as BetterAuthError } from "../error-CMXuwPsa.mjs";
1
+ import "../env-DbssmzoK.mjs";
2
+ import "../utils-NloIXYE0.mjs";
3
+ import { n as BASE_ERROR_CODES, t as BetterAuthError } from "../error-CzMAIrPb.mjs";
4
4
 
5
5
  export { BASE_ERROR_CODES, BetterAuthError };
@@ -1,4 +1,4 @@
1
- import { i as defineErrorCodes } from "./utils-BqQC77zO.mjs";
1
+ import { i as defineErrorCodes } from "./utils-NloIXYE0.mjs";
2
2
 
3
3
  //#region src/error/codes.ts
4
4
  const BASE_ERROR_CODES = defineErrorCodes({
@@ -1,4 +1,4 @@
1
- import { i as Logger, o as createLogger } from "./index-D4vfN5ui.mjs";
1
+ import { i as Logger, o as createLogger } from "./index-BRBu0-5h.mjs";
2
2
  import * as z from "zod";
3
3
  import { BetterFetch, BetterFetchOption, BetterFetchPlugin } from "@better-fetch/fetch";
4
4
  import * as jose0 from "jose";
@@ -924,7 +924,7 @@ type DBAdapter<Options extends BetterAuthOptions = BetterAuthOptions> = {
924
924
  where: Where[];
925
925
  update: Record<string, any>;
926
926
  }) => Promise<number>;
927
- delete: <T>(data: {
927
+ delete: <_T>(data: {
928
928
  model: string;
929
929
  where: Where[];
930
930
  }) => Promise<void>;
@@ -7461,7 +7461,7 @@ type BetterAuthOptions = {
7461
7461
  type GenericEndpointContext<Options extends BetterAuthOptions = BetterAuthOptions> = EndpointContext<string, any> & {
7462
7462
  context: AuthContext<Options>;
7463
7463
  };
7464
- interface InternalAdapter<Options extends BetterAuthOptions = BetterAuthOptions> {
7464
+ interface InternalAdapter<_Options extends BetterAuthOptions = BetterAuthOptions> {
7465
7465
  createOAuthUser(user: Omit<User, "id" | "createdAt" | "updatedAt">, account: Omit<Account, "userId" | "id" | "createdAt" | "updatedAt"> & Partial<Account>): Promise<{
7466
7466
  user: User;
7467
7467
  account: Account;
package/dist/index.d.mts CHANGED
@@ -1,2 +1,2 @@
1
- import { _ as BetterAuthRateLimitOptions, b as HookEndpointContext, c as BetterAuthClientPlugin, d as ClientStore, f as AuthContext, g as BetterAuthOptions, h as BetterAuthAdvancedOptions, hr as Prettify, kn as BetterAuthCookies, l as ClientAtomListener, m as InternalAdapter, mr as LiteralUnion, o as StandardSchemaV1, p as GenericEndpointContext, pr as LiteralString, s as BetterAuthClientOptions, u as ClientFetchOption, v as GenerateIdFn, y as BetterAuthPlugin } from "./index-D6KwwQy5.mjs";
1
+ import { _ as BetterAuthRateLimitOptions, b as HookEndpointContext, c as BetterAuthClientPlugin, d as ClientStore, f as AuthContext, g as BetterAuthOptions, h as BetterAuthAdvancedOptions, hr as Prettify, kn as BetterAuthCookies, l as ClientAtomListener, m as InternalAdapter, mr as LiteralUnion, o as StandardSchemaV1, p as GenericEndpointContext, pr as LiteralString, s as BetterAuthClientOptions, u as ClientFetchOption, v as GenerateIdFn, y as BetterAuthPlugin } from "./index-CH_f5upI.mjs";
2
2
  export { AuthContext, BetterAuthAdvancedOptions, BetterAuthClientOptions, BetterAuthClientPlugin, BetterAuthCookies, BetterAuthOptions, BetterAuthPlugin, BetterAuthRateLimitOptions, ClientAtomListener, ClientFetchOption, ClientStore, GenerateIdFn, GenericEndpointContext, HookEndpointContext, InternalAdapter, LiteralString, LiteralUnion, Prettify, StandardSchemaV1 };
@@ -1,2 +1,2 @@
1
- import { An as createAuthorizationCodeRequest, Bn as OAuth2Tokens, Fn as createRefreshAccessTokenRequest, Hn as OAuthProvider, In as refreshAccessToken, Ln as createAuthorizationURL, Mn as validateToken, Nn as generateCodeChallenge, Pn as getOAuth2Tokens, Rn as clientCredentialsToken, Un as ProviderOptions, Vn as OAuth2UserInfo, jn as validateAuthorizationCode, zn as createClientCredentialsTokenRequest } from "../index-D6KwwQy5.mjs";
1
+ import { An as createAuthorizationCodeRequest, Bn as OAuth2Tokens, Fn as createRefreshAccessTokenRequest, Hn as OAuthProvider, In as refreshAccessToken, Ln as createAuthorizationURL, Mn as validateToken, Nn as generateCodeChallenge, Pn as getOAuth2Tokens, Rn as clientCredentialsToken, Un as ProviderOptions, Vn as OAuth2UserInfo, jn as validateAuthorizationCode, zn as createClientCredentialsTokenRequest } from "../index-CH_f5upI.mjs";
2
2
  export { OAuth2Tokens, OAuth2UserInfo, OAuthProvider, ProviderOptions, clientCredentialsToken, createAuthorizationCodeRequest, createAuthorizationURL, createClientCredentialsTokenRequest, createRefreshAccessTokenRequest, generateCodeChallenge, getOAuth2Tokens, refreshAccessToken, validateAuthorizationCode, validateToken };
@@ -1,3 +1,3 @@
1
- import { a as refreshAccessToken, c as getOAuth2Tokens, i as createRefreshAccessTokenRequest, l as clientCredentialsToken, n as validateAuthorizationCode, o as createAuthorizationURL, r as validateToken, s as generateCodeChallenge, t as createAuthorizationCodeRequest, u as createClientCredentialsTokenRequest } from "../oauth2-7k48hhcV.mjs";
1
+ import { a as refreshAccessToken, c as getOAuth2Tokens, i as createRefreshAccessTokenRequest, l as clientCredentialsToken, n as validateAuthorizationCode, o as createAuthorizationURL, r as validateToken, s as generateCodeChallenge, t as createAuthorizationCodeRequest, u as createClientCredentialsTokenRequest } from "../oauth2-D2y9ALiO.mjs";
2
2
 
3
3
  export { clientCredentialsToken, createAuthorizationCodeRequest, createAuthorizationURL, createClientCredentialsTokenRequest, createRefreshAccessTokenRequest, generateCodeChallenge, getOAuth2Tokens, refreshAccessToken, validateAuthorizationCode, validateToken };
@@ -1,2 +1,2 @@
1
- import { $ as AccountStatus, $t as GoogleProfile, A as PolarOptions, At as linear, B as LineIdTokenPayload, Bt as TwitchOptions, C as SocialProviderListEnum, Cn as atlassian, Ct as gitlab, D as VercelOptions, Dn as apple, Dt as LinearOptions, E as socialProviders, En as AppleProfile, Et as linkedin, F as PayPalTokenResponse, Ft as DropboxProfile, G as NaverProfile, Gt as spotify, H as LineUserInfo, Ht as twitch, I as paypal, It as dropbox, J as KakaoProfile, Jt as slack, K as naver, Kt as SlackOptions, L as PaybinOptions, Lt as TwitterOption, M as polar, Mt as KickProfile, N as PayPalOptions, Nt as kick, O as VercelProfile, On as getApplePublicKey, Ot as LinearProfile, P as PayPalProfile, Pt as DropboxOptions, Q as notion, Qt as GoogleOptions, R as PaybinProfile, Rt as TwitterProfile, S as SocialProviderList, Sn as AtlassianProfile, St as GitlabProfile, T as socialProviderList, Tn as AppleOptions, Tt as LinkedInProfile, U as line, Ut as SpotifyOptions, V as LineOptions, Vt as TwitchProfile, W as NaverOptions, Wt as SpotifyProfile, X as NotionOptions, Xt as HuggingFaceProfile, Y as kakao, Yt as HuggingFaceOptions, Z as NotionProfile, Zt as huggingface, _n as CognitoOptions, _t as reddit, an as GithubOptions, at as zoom, bn as getCognitoPublicKey, bt as tiktok, cn as FigmaOptions, ct as vk, dn as FacebookOptions, dt as salesforce, en as getGooglePublicKey, et as LoginType, fn as FacebookProfile, ft as RobloxOptions, gn as discord, gt as RedditProfile, hn as DiscordProfile, ht as RedditOptions, in as microsoft, it as ZoomProfile, j as PolarProfile, jt as KickOptions, k as vercel, kt as LinearUser, ln as FigmaProfile, lt as SalesforceOptions, mn as DiscordOptions, mt as roblox, nn as MicrosoftEntraIDProfile, nt as PronounOption, on as GithubProfile, ot as VkOption, pn as facebook, pt as RobloxProfile, q as KakaoOptions, qt as SlackProfile, rn as MicrosoftOptions, rt as ZoomOptions, sn as github, st as VkProfile, tn as google, tt as PhoneNumber, un as figma, ut as SalesforceProfile, vn as CognitoProfile, vt as TiktokOptions, w as SocialProviders, wn as AppleNonConformUser, wt as LinkedInOptions, x as SocialProvider, xn as AtlassianOptions, xt as GitlabOptions, yn as cognito, yt as TiktokProfile, z as paybin, zt as twitter } from "../index-D6KwwQy5.mjs";
1
+ import { $ as AccountStatus, $t as GoogleProfile, A as PolarOptions, At as linear, B as LineIdTokenPayload, Bt as TwitchOptions, C as SocialProviderListEnum, Cn as atlassian, Ct as gitlab, D as VercelOptions, Dn as apple, Dt as LinearOptions, E as socialProviders, En as AppleProfile, Et as linkedin, F as PayPalTokenResponse, Ft as DropboxProfile, G as NaverProfile, Gt as spotify, H as LineUserInfo, Ht as twitch, I as paypal, It as dropbox, J as KakaoProfile, Jt as slack, K as naver, Kt as SlackOptions, L as PaybinOptions, Lt as TwitterOption, M as polar, Mt as KickProfile, N as PayPalOptions, Nt as kick, O as VercelProfile, On as getApplePublicKey, Ot as LinearProfile, P as PayPalProfile, Pt as DropboxOptions, Q as notion, Qt as GoogleOptions, R as PaybinProfile, Rt as TwitterProfile, S as SocialProviderList, Sn as AtlassianProfile, St as GitlabProfile, T as socialProviderList, Tn as AppleOptions, Tt as LinkedInProfile, U as line, Ut as SpotifyOptions, V as LineOptions, Vt as TwitchProfile, W as NaverOptions, Wt as SpotifyProfile, X as NotionOptions, Xt as HuggingFaceProfile, Y as kakao, Yt as HuggingFaceOptions, Z as NotionProfile, Zt as huggingface, _n as CognitoOptions, _t as reddit, an as GithubOptions, at as zoom, bn as getCognitoPublicKey, bt as tiktok, cn as FigmaOptions, ct as vk, dn as FacebookOptions, dt as salesforce, en as getGooglePublicKey, et as LoginType, fn as FacebookProfile, ft as RobloxOptions, gn as discord, gt as RedditProfile, hn as DiscordProfile, ht as RedditOptions, in as microsoft, it as ZoomProfile, j as PolarProfile, jt as KickOptions, k as vercel, kt as LinearUser, ln as FigmaProfile, lt as SalesforceOptions, mn as DiscordOptions, mt as roblox, nn as MicrosoftEntraIDProfile, nt as PronounOption, on as GithubProfile, ot as VkOption, pn as facebook, pt as RobloxProfile, q as KakaoOptions, qt as SlackProfile, rn as MicrosoftOptions, rt as ZoomOptions, sn as github, st as VkProfile, tn as google, tt as PhoneNumber, un as figma, ut as SalesforceProfile, vn as CognitoProfile, vt as TiktokOptions, w as SocialProviders, wn as AppleNonConformUser, wt as LinkedInOptions, x as SocialProvider, xn as AtlassianOptions, xt as GitlabOptions, yn as cognito, yt as TiktokProfile, z as paybin, zt as twitter } from "../index-CH_f5upI.mjs";
2
2
  export { AccountStatus, AppleNonConformUser, AppleOptions, AppleProfile, AtlassianOptions, AtlassianProfile, CognitoOptions, CognitoProfile, DiscordOptions, DiscordProfile, DropboxOptions, DropboxProfile, FacebookOptions, FacebookProfile, FigmaOptions, FigmaProfile, GithubOptions, GithubProfile, GitlabOptions, GitlabProfile, GoogleOptions, GoogleProfile, HuggingFaceOptions, HuggingFaceProfile, KakaoOptions, KakaoProfile, KickOptions, KickProfile, LineIdTokenPayload, LineOptions, LineUserInfo, LinearOptions, LinearProfile, LinearUser, LinkedInOptions, LinkedInProfile, LoginType, MicrosoftEntraIDProfile, MicrosoftOptions, NaverOptions, NaverProfile, NotionOptions, NotionProfile, PayPalOptions, PayPalProfile, PayPalTokenResponse, PaybinOptions, PaybinProfile, PhoneNumber, PolarOptions, PolarProfile, PronounOption, RedditOptions, RedditProfile, RobloxOptions, RobloxProfile, SalesforceOptions, SalesforceProfile, SlackOptions, SlackProfile, SocialProvider, SocialProviderList, SocialProviderListEnum, SocialProviders, SpotifyOptions, SpotifyProfile, TiktokOptions, TiktokProfile, TwitchOptions, TwitchProfile, TwitterOption, TwitterProfile, VercelOptions, VercelProfile, VkOption, VkProfile, ZoomOptions, ZoomProfile, apple, atlassian, cognito, discord, dropbox, facebook, figma, getApplePublicKey, getCognitoPublicKey, getGooglePublicKey, github, gitlab, google, huggingface, kakao, kick, line, linear, linkedin, microsoft, naver, notion, paybin, paypal, polar, reddit, roblox, salesforce, slack, socialProviderList, socialProviders, spotify, tiktok, twitch, twitter, vercel, vk, zoom };
@@ -1,7 +1,7 @@
1
- import { i as logger } from "../env-D6s-lvJz.mjs";
2
- import "../utils-BqQC77zO.mjs";
3
- import { t as BetterAuthError } from "../error-CMXuwPsa.mjs";
4
- import { a as refreshAccessToken, c as getOAuth2Tokens, n as validateAuthorizationCode, o as createAuthorizationURL, s as generateCodeChallenge } from "../oauth2-7k48hhcV.mjs";
1
+ import { i as logger } from "../env-DbssmzoK.mjs";
2
+ import "../utils-NloIXYE0.mjs";
3
+ import { t as BetterAuthError } from "../error-CzMAIrPb.mjs";
4
+ import { a as refreshAccessToken, c as getOAuth2Tokens, n as validateAuthorizationCode, o as createAuthorizationURL, s as generateCodeChallenge } from "../oauth2-D2y9ALiO.mjs";
5
5
  import * as z from "zod";
6
6
  import { base64 } from "@better-auth/utils/base64";
7
7
  import { betterFetch } from "@better-fetch/fetch";
@@ -484,7 +484,7 @@ const facebook = (options) => {
484
484
  });
485
485
  if (nonce && jwtClaims.nonce !== nonce) return false;
486
486
  return !!jwtClaims;
487
- } catch (error) {
487
+ } catch {
488
488
  return false;
489
489
  }
490
490
  return true;
@@ -1,4 +1,4 @@
1
- import "../env-D6s-lvJz.mjs";
2
- import { i as defineErrorCodes, n as safeJSONParse, r as generateId, t as capitalizeFirstLetter } from "../utils-BqQC77zO.mjs";
1
+ import "../env-DbssmzoK.mjs";
2
+ import { i as defineErrorCodes, n as safeJSONParse, r as generateId, t as capitalizeFirstLetter } from "../utils-NloIXYE0.mjs";
3
3
 
4
4
  export { capitalizeFirstLetter, defineErrorCodes, generateId, safeJSONParse };
@@ -1,4 +1,4 @@
1
- import { i as logger } from "./env-D6s-lvJz.mjs";
1
+ import { i as logger } from "./env-DbssmzoK.mjs";
2
2
  import { createRandomStringGenerator } from "@better-auth/utils/random";
3
3
 
4
4
  //#region src/utils/error-codes.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@better-auth/core",
3
- "version": "1.4.6",
3
+ "version": "1.4.7-beta.2",
4
4
  "description": "The most comprehensive authentication framework for TypeScript.",
5
5
  "type": "module",
6
6
  "repository": {
@@ -25,6 +25,12 @@
25
25
  "./async_hooks": {
26
26
  "dev-source": "./src/async_hooks/index.ts",
27
27
  "types": "./dist/async_hooks/index.d.mts",
28
+ "node": "./dist/async_hooks/index.mjs",
29
+ "deno": "./dist/async_hooks/index.mjs",
30
+ "bun": "./dist/async_hooks/index.mjs",
31
+ "edge": "./dist/async_hooks/pure.index.mjs",
32
+ "workerd": "./dist/async_hooks/index.mjs",
33
+ "browser": "./dist/async_hooks/pure.index.mjs",
28
34
  "default": "./dist/async_hooks/index.mjs"
29
35
  },
30
36
  "./context": {
@@ -112,7 +118,7 @@
112
118
  "jose": "^6.1.0",
113
119
  "kysely": "^0.28.5",
114
120
  "nanostores": "^1.0.1",
115
- "tsdown": "^0.17.0"
121
+ "tsdown": "^0.17.2"
116
122
  },
117
123
  "dependencies": {
118
124
  "@standard-schema/spec": "^1.0.0",
@@ -130,6 +136,7 @@
130
136
  "build": "tsdown",
131
137
  "dev": "tsdown --watch",
132
138
  "lint:package": "publint run --strict",
139
+ "lint:types": "attw --profile esm-only --pack .",
133
140
  "typecheck": "tsc --project tsconfig.json",
134
141
  "test": "vitest",
135
142
  "coverage": "vitest run --coverage"
@@ -1,34 +1,7 @@
1
1
  import type { AsyncLocalStorage } from "node:async_hooks";
2
- import { env } from "../env";
3
2
 
4
3
  export type { AsyncLocalStorage };
5
4
 
6
- /**
7
- * Due to the lack of AsyncLocalStorage in some environments (like Convex),
8
- *
9
- * We assume serverless functions are short-lived and single-threaded, so we can use a simple polyfill.
10
- */
11
- class AsyncLocalStoragePolyfill<T> {
12
- #current: T | undefined = undefined;
13
-
14
- run(store: T, fn: () => unknown): unknown {
15
- const prev = this.#current;
16
- this.#current = store;
17
- const result = fn();
18
- if (result instanceof Promise) {
19
- return result.finally(() => {
20
- this.#current = prev;
21
- });
22
- }
23
- this.#current = prev;
24
- return result;
25
- }
26
-
27
- getStore(): T | undefined {
28
- return this.#current;
29
- }
30
- }
31
-
32
5
  const AsyncLocalStoragePromise: Promise<typeof AsyncLocalStorage | null> =
33
6
  import(
34
7
  /* @vite-ignore */
@@ -43,9 +16,6 @@ const AsyncLocalStoragePromise: Promise<typeof AsyncLocalStorage | null> =
43
16
  if (typeof window !== "undefined") {
44
17
  return null;
45
18
  }
46
- if (env["CONVEX_CLOUD_URL"] || env["CONVEX_SITE_URL"]) {
47
- return AsyncLocalStoragePolyfill;
48
- }
49
19
  console.warn(
50
20
  "[better-auth] Warning: AsyncLocalStorage is not available in this environment. Some features may not work as expected.",
51
21
  );
@@ -0,0 +1,46 @@
1
+ import type { AsyncLocalStorage } from "node:async_hooks";
2
+
3
+ /**
4
+ * Due to the lack of AsyncLocalStorage in some environments (like Convex),
5
+ *
6
+ * We assume serverless functions are short-lived and single-threaded, so we can use a simple polyfill.
7
+ */
8
+ class AsyncLocalStoragePolyfill<T> {
9
+ #current: T | undefined = undefined;
10
+
11
+ run(store: T, fn: () => unknown): unknown {
12
+ const prev = this.#current;
13
+ this.#current = store;
14
+ const result = fn();
15
+ if (result instanceof Promise) {
16
+ return result.finally(() => {
17
+ this.#current = prev;
18
+ });
19
+ }
20
+ this.#current = prev;
21
+ return result;
22
+ }
23
+
24
+ getStore(): T | undefined {
25
+ return this.#current;
26
+ }
27
+ }
28
+
29
+ const AsyncLocalStoragePromise: Promise<typeof AsyncLocalStorage | null> =
30
+ Promise.resolve().then(() => {
31
+ if ("AsyncLocalStorage" in globalThis) {
32
+ return (globalThis as any).AsyncLocalStorage;
33
+ }
34
+ return AsyncLocalStoragePolyfill;
35
+ });
36
+
37
+ export async function getAsyncLocalStorage(): Promise<
38
+ typeof AsyncLocalStorage
39
+ > {
40
+ const mod = await AsyncLocalStoragePromise;
41
+ if (mod === null) {
42
+ throw new Error("getAsyncLocalStorage is only available in server code");
43
+ } else {
44
+ return mod;
45
+ }
46
+ }
@@ -1,6 +1,6 @@
1
+ import type { AsyncLocalStorage } from "@better-auth/core/async_hooks";
2
+ import { getAsyncLocalStorage } from "@better-auth/core/async_hooks";
1
3
  import type { EndpointContext, InputContext } from "better-call";
2
- import type { AsyncLocalStorage } from "../async_hooks";
3
- import { getAsyncLocalStorage } from "../async_hooks";
4
4
  import type { AuthContext } from "../types";
5
5
 
6
6
  export type AuthEndpointContext = Partial<
@@ -1,5 +1,5 @@
1
- import type { AsyncLocalStorage } from "../async_hooks";
2
- import { getAsyncLocalStorage } from "../async_hooks";
1
+ import type { AsyncLocalStorage } from "@better-auth/core/async_hooks";
2
+ import { getAsyncLocalStorage } from "@better-auth/core/async_hooks";
3
3
 
4
4
  export type RequestStateWeakMap = WeakMap<object, any>;
5
5
 
@@ -1,5 +1,5 @@
1
- import type { AsyncLocalStorage } from "../async_hooks";
2
- import { getAsyncLocalStorage } from "../async_hooks";
1
+ import type { AsyncLocalStorage } from "@better-auth/core/async_hooks";
2
+ import { getAsyncLocalStorage } from "@better-auth/core/async_hooks";
3
3
  import type { DBAdapter, DBTransactionAdapter } from "../db/adapter";
4
4
 
5
5
  let currentAdapterAsyncStorage: AsyncLocalStorage<DBTransactionAdapter> | null =
@@ -424,7 +424,7 @@ export type DBAdapter<Options extends BetterAuthOptions = BetterAuthOptions> = {
424
424
  where: Where[];
425
425
  update: Record<string, any>;
426
426
  }) => Promise<number>;
427
- delete: <T>(data: { model: string; where: Where[] }) => Promise<void>;
427
+ delete: <_T>(data: { model: string; where: Where[] }) => Promise<void>;
428
428
  deleteMany: (data: { model: string; where: Where[] }) => Promise<number>;
429
429
  /**
430
430
  * Execute multiple operations in a transaction.
@@ -102,7 +102,7 @@ export const facebook = (options: FacebookOptions) => {
102
102
  }
103
103
 
104
104
  return !!jwtClaims;
105
- } catch (error) {
105
+ } catch {
106
106
  return false;
107
107
  }
108
108
  }
@@ -24,7 +24,7 @@ export type GenericEndpointContext<
24
24
  };
25
25
 
26
26
  export interface InternalAdapter<
27
- Options extends BetterAuthOptions = BetterAuthOptions,
27
+ _Options extends BetterAuthOptions = BetterAuthOptions,
28
28
  > {
29
29
  createOAuthUser(
30
30
  user: Omit<User, "id" | "createdAt" | "updatedAt">,
package/tsdown.config.ts CHANGED
@@ -8,6 +8,7 @@ export default defineConfig({
8
8
  "./src/db/index.ts",
9
9
  "./src/db/adapter/index.ts",
10
10
  "./src/async_hooks/index.ts",
11
+ "./src/async_hooks/pure.index.ts",
11
12
  "./src/context/index.ts",
12
13
  "./src/env/index.ts",
13
14
  "./src/oauth2/index.ts",
@@ -16,5 +17,6 @@ export default defineConfig({
16
17
  "./src/utils/index.ts",
17
18
  "./src/error/index.ts",
18
19
  ],
20
+ external: ["@better-auth/core/async_hooks"],
19
21
  clean: true,
20
22
  });
@@ -1,45 +0,0 @@
1
- import { c as env } from "./env-D6s-lvJz.mjs";
2
-
3
- //#region src/async_hooks/index.ts
4
- /**
5
- * Due to the lack of AsyncLocalStorage in some environments (like Convex),
6
- *
7
- * We assume serverless functions are short-lived and single-threaded, so we can use a simple polyfill.
8
- */
9
- var AsyncLocalStoragePolyfill = class {
10
- #current = void 0;
11
- run(store, fn) {
12
- const prev = this.#current;
13
- this.#current = store;
14
- const result = fn();
15
- if (result instanceof Promise) return result.finally(() => {
16
- this.#current = prev;
17
- });
18
- this.#current = prev;
19
- return result;
20
- }
21
- getStore() {
22
- return this.#current;
23
- }
24
- };
25
- const AsyncLocalStoragePromise = import(
26
- /* @vite-ignore */
27
- /* webpackIgnore: true */
28
- "node:async_hooks"
29
- ).then((mod) => mod.AsyncLocalStorage).catch((err) => {
30
- if ("AsyncLocalStorage" in globalThis) return globalThis.AsyncLocalStorage;
31
- if (typeof window !== "undefined") return null;
32
- if (env["CONVEX_CLOUD_URL"] || env["CONVEX_SITE_URL"]) return AsyncLocalStoragePolyfill;
33
- console.warn("[better-auth] Warning: AsyncLocalStorage is not available in this environment. Some features may not work as expected.");
34
- console.warn("[better-auth] Please read more about this warning at https://better-auth.com/docs/installation#mount-handler");
35
- console.warn("[better-auth] If you are using Cloudflare Workers, please see: https://developers.cloudflare.com/workers/configuration/compatibility-flags/#nodejs-compatibility-flag");
36
- throw err;
37
- });
38
- async function getAsyncLocalStorage() {
39
- const mod = await AsyncLocalStoragePromise;
40
- if (mod === null) throw new Error("getAsyncLocalStorage is only available in server code");
41
- else return mod;
42
- }
43
-
44
- //#endregion
45
- export { getAsyncLocalStorage as t };
@@ -1,12 +0,0 @@
1
- import { expect, test, vi } from "vitest";
2
-
3
- vi.mock(import("node:async_hooks"), () => {
4
- throw new Error("Doesn't work with convex");
5
- });
6
-
7
- test("should work with convex", async () => {
8
- vi.stubEnv("CONVEX_CLOUD_URL", "https://convex.com");
9
- vi.stubEnv("CONVEX_SITE_URL", "http://test.com");
10
- const { getAsyncLocalStorage } = await import(".");
11
- await expect(getAsyncLocalStorage()).to.resolves.toBeDefined();
12
- });
File without changes