@better-auth/core 1.4.10 → 1.4.11-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.
@@ -1,5 +1,5 @@
1
1
 
2
- > @better-auth/core@1.4.10 build /home/runner/work/better-auth/better-auth/packages/core
2
+ > @better-auth/core@1.4.11-beta.2 build /home/runner/work/better-auth/better-auth/packages/core
3
3
  > tsdown
4
4
 
5
5
  ℹ tsdown v0.17.2 powered by rolldown v1.0.0-beta.53
@@ -16,28 +16,28 @@
16
16
  ℹ dist/oauth2/index.mjs  0.75 kB │ gzip: 0.28 kB
17
17
  ℹ dist/context/index.mjs  0.70 kB │ gzip: 0.24 kB
18
18
  ℹ dist/env/index.mjs  0.44 kB │ gzip: 0.25 kB
19
- ℹ dist/utils/index.mjs  0.24 kB │ gzip: 0.17 kB
19
+ ℹ dist/utils/index.mjs  0.26 kB │ gzip: 0.18 kB
20
20
  ℹ dist/error/index.mjs  0.19 kB │ gzip: 0.14 kB
21
21
  ℹ dist/index.mjs  0.01 kB │ gzip: 0.03 kB
22
22
  ℹ dist/oauth2-BjWM15hm.mjs  12.82 kB │ gzip: 3.16 kB
23
23
  ℹ dist/env-DbssmzoK.mjs  7.67 kB │ gzip: 2.54 kB
24
24
  ℹ dist/get-tables-CMc_Emww.mjs  6.76 kB │ gzip: 1.30 kB
25
- ℹ dist/context-DblZrIwO.mjs  3.89 kB │ gzip: 1.00 kB
26
- ℹ dist/error-RtKwr3Pu.mjs  2.76 kB │ gzip: 1.16 kB
27
- ℹ dist/utils-NloIXYE0.mjs  1.10 kB │ gzip: 0.55 kB
28
- ℹ dist/social-providers/index.d.mts  3.88 kB │ gzip: 1.19 kB
25
+ ℹ dist/context-BBNwughv.mjs  4.87 kB │ gzip: 1.40 kB
26
+ ℹ dist/error-DP1xOn7P.mjs  2.76 kB │ gzip: 1.16 kB
27
+ ℹ dist/utils-U2L7n92V.mjs  1.46 kB │ gzip: 0.70 kB
28
+ ℹ dist/social-providers/index.d.mts  3.89 kB │ gzip: 1.19 kB
29
29
  ℹ dist/context/index.d.mts  3.02 kB │ gzip: 0.96 kB
30
30
  ℹ dist/error/index.d.mts  3.02 kB │ gzip: 1.10 kB
31
+ ℹ dist/utils/index.d.mts  1.50 kB │ gzip: 0.68 kB
31
32
  ℹ dist/db/adapter/index.d.mts  1.34 kB │ gzip: 0.43 kB
32
- ℹ dist/utils/index.d.mts  1.19 kB │ gzip: 0.55 kB
33
- ℹ dist/index.d.mts  0.92 kB │ gzip: 0.35 kB
33
+ ℹ dist/index.d.mts  0.95 kB │ gzip: 0.36 kB
34
34
  ℹ dist/oauth2/index.d.mts  0.88 kB │ gzip: 0.32 kB
35
35
  ℹ dist/db/index.d.mts  0.81 kB │ gzip: 0.34 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
38
  ℹ dist/async_hooks/index.d.mts  0.24 kB │ gzip: 0.16 kB
39
39
  ℹ dist/async_hooks/pure.index.d.mts  0.22 kB │ gzip: 0.16 kB
40
- ℹ dist/index-1XS3AkXa.d.mts 221.47 kB │ gzip: 35.34 kB
40
+ ℹ dist/index-eRGNbXt_.d.mts 227.31 kB │ gzip: 35.80 kB
41
41
  ℹ dist/index-BRBu0-5h.d.mts  3.31 kB │ gzip: 1.11 kB
42
- ℹ 32 files, total: 402.93 kB
43
- ✔ Build complete in 4911ms
42
+ ℹ 32 files, total: 410.48 kB
43
+ ✔ Build complete in 5228ms
@@ -1,2 +1,2 @@
1
- import { a as optionsMiddleware, i as createAuthMiddleware, n as AuthMiddleware, r as createAuthEndpoint, t as AuthEndpoint } from "../index-1XS3AkXa.mjs";
1
+ import { a as optionsMiddleware, i as createAuthMiddleware, n as AuthMiddleware, r as createAuthEndpoint, t as AuthEndpoint } from "../index-eRGNbXt_.mjs";
2
2
  export { AuthEndpoint, AuthMiddleware, createAuthEndpoint, createAuthMiddleware, optionsMiddleware };
@@ -1,4 +1,4 @@
1
- import { f as runWithEndpointContext } from "../context-DblZrIwO.mjs";
1
+ import { f as runWithEndpointContext } from "../context-BBNwughv.mjs";
2
2
  import { createEndpoint, createMiddleware } from "better-call";
3
3
 
4
4
  //#region src/api/index.ts
@@ -1,4 +1,4 @@
1
- import { Yn as DBAdapter, er as DBTransactionAdapter, f as AuthContext } from "../index-1XS3AkXa.mjs";
1
+ import { Xn as DBAdapter, f as AuthContext, tr as DBTransactionAdapter } from "../index-eRGNbXt_.mjs";
2
2
  import { AsyncLocalStorage } from "@better-auth/core/async_hooks";
3
3
  import { EndpointContext, InputContext } from "better-call";
4
4
 
@@ -1,3 +1,3 @@
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";
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-BBNwughv.mjs";
2
2
 
3
3
  export { defineRequestState, getCurrentAdapter, getCurrentAuthContext, getCurrentAuthContextAsyncLocalStorage, getCurrentDBAdapterAsyncLocalStorage, getCurrentRequestState, getRequestStateAsyncLocalStorage, hasRequestState, runWithAdapter, runWithEndpointContext, runWithRequestState, runWithTransaction };
@@ -110,5 +110,24 @@ const runWithTransaction = async (adapter, fn) => {
110
110
  });
111
111
  };
112
112
 
113
+ //#endregion
114
+ //#region src/context/index.ts
115
+ const glo = typeof globalThis !== "undefined" ? globalThis : typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : {};
116
+ const importIdentifier = "__ $BETTER_AUTH$ __";
117
+ if (glo[importIdentifier] === true)
118
+ /**
119
+ * Dear reader of this message. Please take this seriously.
120
+ *
121
+ * If you see this message, make sure that you only import one version of Better Auth. In many cases,
122
+ * your package manager installs two versions of Better Auth that are used by different packages within your project.
123
+ *
124
+ * This often leads to issues that are hard to debug. We often need to ensure async local storage instance,
125
+ * If you imported different versions of Better Auth, it is impossible for us to
126
+ * do status synchronization per request anymore - which might break the states.
127
+ *
128
+ */
129
+ console.error("Better Auth was already imported. This breaks async local storage instance and will lead to issues!");
130
+ glo[importIdentifier] = true;
131
+
113
132
  //#endregion
114
133
  export { defineRequestState as a, hasRequestState as c, getCurrentAuthContextAsyncLocalStorage as d, runWithEndpointContext as f, runWithTransaction as i, runWithRequestState as l, getCurrentDBAdapterAsyncLocalStorage as n, getCurrentRequestState as o, runWithAdapter as r, getRequestStateAsyncLocalStorage as s, getCurrentAdapter as t, getCurrentAuthContext as u };
@@ -1,2 +1,2 @@
1
- import { $n as DBAdapterSchemaCreation, Cr as initGetFieldName, Er as initGetDefaultFieldName, Jn as CustomAdapter, Qn as DBAdapterInstance, Sr as initGetIdField, Tr as initGetDefaultModelName, Xn as DBAdapterDebugLogOption, Yn as DBAdapter, Zn as DBAdapterFactoryConfig, ar as withApplyDefault, cr as createAdapterFactory, dr as AdapterFactoryCustomizeAdapterCreator, er as DBTransactionAdapter, fr as AdapterFactoryOptions, hr as CreateCustomAdapter, ir as deepmerge, lr as AdapterConfig, mr as CreateAdapterOptions, nr as JoinOption, or as AdapterFactory, pr as AdapterTestDebugLogs, qn as CleanedWhere, rr as Where, sr as createAdapter, tr as JoinConfig, ur as AdapterFactoryConfig, wr as initGetFieldAttributes, xr as initGetModelName } from "../../index-1XS3AkXa.mjs";
1
+ import { $n as DBAdapterInstance, Cr as initGetIdField, Dr as initGetDefaultFieldName, Er as initGetDefaultModelName, Jn as CleanedWhere, Qn as DBAdapterFactoryConfig, Sr as initGetModelName, Tr as initGetFieldAttributes, Xn as DBAdapter, Yn as CustomAdapter, Zn as DBAdapterDebugLogOption, ar as deepmerge, cr as createAdapter, dr as AdapterFactoryConfig, er as DBAdapterSchemaCreation, fr as AdapterFactoryCustomizeAdapterCreator, gr as CreateCustomAdapter, hr as CreateAdapterOptions, ir as Where, lr as createAdapterFactory, mr as AdapterTestDebugLogs, nr as JoinConfig, or as withApplyDefault, pr as AdapterFactoryOptions, rr as JoinOption, sr as AdapterFactory, tr as DBTransactionAdapter, ur as AdapterConfig, wr as initGetFieldName } from "../../index-eRGNbXt_.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
1
  import { t as getAuthTables } from "../../get-tables-CMc_Emww.mjs";
2
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-RtKwr3Pu.mjs";
3
+ import { n as safeJSONParse, r as generateId } from "../../utils-U2L7n92V.mjs";
4
+ import { t as BetterAuthError } from "../../error-DP1xOn7P.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 userSchema, Br as BaseModelNames, Dr as Verification, Fr as rateLimitSchema, Gr as DBPrimitive, Hr as DBFieldAttribute, Ir as Account, Kr as ModelNames, Lr as accountSchema, Mr as Session, Nr as sessionSchema, Or as verificationSchema, Pr as RateLimit, Rr as BetterAuthPluginDBSchema, Ur as DBFieldAttributeConfig, Vr as BetterAuthDBSchema, Wr as DBFieldType, jr as coreSchema, kr as User, qr as SecondaryStorage, zr as getAuthTables } from "../index-1XS3AkXa.mjs";
1
+ import { Ar as User, Br as getAuthTables, Fr as RateLimit, Gr as DBFieldType, Hr as BetterAuthDBSchema, Ir as rateLimitSchema, Jr as SecondaryStorage, Kr as DBPrimitive, Lr as Account, Mr as coreSchema, Nr as Session, Or as Verification, Pr as sessionSchema, Rr as accountSchema, Ur as DBFieldAttribute, Vr as BaseModelNames, Wr as DBFieldAttributeConfig, jr as userSchema, kr as verificationSchema, qr as ModelNames, zr as BetterAuthPluginDBSchema } from "../index-eRGNbXt_.mjs";
2
2
  export { Account, BaseModelNames, BetterAuthDBSchema, BetterAuthPluginDBSchema, DBFieldAttribute, DBFieldAttributeConfig, DBFieldType, DBPrimitive, ModelNames, RateLimit, SecondaryStorage, Session, User, Verification, accountSchema, coreSchema, getAuthTables, rateLimitSchema, sessionSchema, userSchema, verificationSchema };
@@ -1,5 +1,5 @@
1
1
  import "../env-DbssmzoK.mjs";
2
- import "../utils-NloIXYE0.mjs";
3
- import { n as BASE_ERROR_CODES, t as BetterAuthError } from "../error-RtKwr3Pu.mjs";
2
+ import "../utils-U2L7n92V.mjs";
3
+ import { n as BASE_ERROR_CODES, t as BetterAuthError } from "../error-DP1xOn7P.mjs";
4
4
 
5
5
  export { BASE_ERROR_CODES, BetterAuthError };
@@ -1,4 +1,4 @@
1
- import { i as defineErrorCodes } from "./utils-NloIXYE0.mjs";
1
+ import { i as defineErrorCodes } from "./utils-U2L7n92V.mjs";
2
2
 
3
3
  //#region src/error/codes.ts
4
4
  const BASE_ERROR_CODES = defineErrorCodes({
@@ -6706,8 +6706,15 @@ type BetterAuthOptions = {
6706
6706
  * A function that is called when a user verifies their email
6707
6707
  * @param user the user that verified their email
6708
6708
  * @param request the request object
6709
+ * @deprecated Use `beforeEmailVerification` or `afterEmailVerification` instead. This will be removed in 1.5
6709
6710
  */
6710
6711
  onEmailVerification?: (user: User, request?: Request) => Promise<void>;
6712
+ /**
6713
+ * A function that is called before a user verifies their email
6714
+ * @param user the user that verified their email
6715
+ * @param request the request object
6716
+ */
6717
+ beforeEmailVerification?: (user: User, request?: Request) => Promise<void>;
6711
6718
  /**
6712
6719
  * A function that is called when a user's email is updated to verified
6713
6720
  * @param user the user that verified their email
@@ -7196,8 +7203,20 @@ type BetterAuthOptions = {
7196
7203
  *
7197
7204
  * Trusted origins will be dynamically
7198
7205
  * calculated based on the request.
7206
+ *
7207
+ * @example
7208
+ * ```ts
7209
+ * trustedOrigins: async (request) => {
7210
+ * return [
7211
+ * "https://better-auth.com",
7212
+ * "https://*.better-auth.com",
7213
+ * request.headers.get("x-custom-origin")
7214
+ * ];
7215
+ * }
7216
+ * ```
7217
+ * @returns An array of trusted origins.
7199
7218
  */
7200
- trustedOrigins?: (string[] | ((request?: Request | undefined) => Awaitable<string[]>)) | undefined;
7219
+ trustedOrigins?: (string[] | ((request?: Request | undefined) => Awaitable<(string | undefined | null)[]>)) | undefined;
7201
7220
  /**
7202
7221
  * Rate limiting configuration
7203
7222
  */
@@ -7574,7 +7593,10 @@ type CreateCookieGetterFn = (cookieName: string, overrideAttributes?: Partial<Co
7574
7593
  attributes: CookieOptions;
7575
7594
  };
7576
7595
  type CheckPasswordFn<Options extends BetterAuthOptions = BetterAuthOptions> = (userId: string, ctx: GenericEndpointContext<Options>) => Promise<boolean>;
7577
- type AuthContext<Options extends BetterAuthOptions = BetterAuthOptions> = {
7596
+ type PluginContext = {
7597
+ getPlugin: <Plugin extends BetterAuthPlugin>(pluginId: Plugin["id"]) => Plugin | null;
7598
+ };
7599
+ type AuthContext<Options extends BetterAuthOptions = BetterAuthOptions> = PluginContext & {
7578
7600
  options: Options;
7579
7601
  appName: string;
7580
7602
  baseURL: string;
@@ -7805,13 +7827,167 @@ interface BetterAuthClientPlugin {
7805
7827
  //#region src/api/index.d.ts
7806
7828
  declare const optionsMiddleware: <InputCtx extends better_call0.MiddlewareInputContext<better_call0.MiddlewareOptions>>(inputContext: InputCtx) => Promise<AuthContext>;
7807
7829
  declare const createAuthMiddleware: {
7808
- <Options extends better_call0.MiddlewareOptions, R>(options: Options, handler: (ctx: better_call0.MiddlewareContext<Options, AuthContext & {
7830
+ <Options extends better_call0.MiddlewareOptions, R>(options: Options, handler: (ctx: better_call0.MiddlewareContext<Options, {
7809
7831
  returned?: unknown | undefined;
7810
7832
  responseHeaders?: Headers | undefined;
7833
+ } & PluginContext & {
7834
+ options: BetterAuthOptions;
7835
+ appName: string;
7836
+ baseURL: string;
7837
+ trustedOrigins: string[];
7838
+ isTrustedOrigin: (url: string, settings?: {
7839
+ allowRelativePaths: boolean;
7840
+ }) => boolean;
7841
+ oauthConfig: {
7842
+ skipStateCookieCheck?: boolean | undefined;
7843
+ storeStateStrategy: "database" | "cookie";
7844
+ };
7845
+ newSession: {
7846
+ session: Session & Record<string, any>;
7847
+ user: User & Record<string, any>;
7848
+ } | null;
7849
+ session: {
7850
+ session: Session & Record<string, any>;
7851
+ user: User & Record<string, any>;
7852
+ } | null;
7853
+ setNewSession: (session: {
7854
+ session: Session & Record<string, any>;
7855
+ user: User & Record<string, any>;
7856
+ } | null) => void;
7857
+ socialProviders: OAuthProvider[];
7858
+ authCookies: BetterAuthCookies;
7859
+ logger: ReturnType<typeof createLogger>;
7860
+ rateLimit: {
7861
+ enabled: boolean;
7862
+ window: number;
7863
+ max: number;
7864
+ storage: "memory" | "database" | "secondary-storage";
7865
+ } & BetterAuthRateLimitOptions;
7866
+ adapter: DBAdapter<BetterAuthOptions>;
7867
+ internalAdapter: InternalAdapter<BetterAuthOptions>;
7868
+ createAuthCookie: (cookieName: string, overrideAttributes?: Partial<better_call0.CookieOptions> | undefined) => {
7869
+ name: string;
7870
+ attributes: better_call0.CookieOptions;
7871
+ };
7872
+ secret: string;
7873
+ sessionConfig: {
7874
+ updateAge: number;
7875
+ expiresIn: number;
7876
+ freshAge: number;
7877
+ cookieRefreshCache: false | {
7878
+ enabled: true;
7879
+ updateAge: number;
7880
+ };
7881
+ };
7882
+ generateId: (options: {
7883
+ model: ModelNames;
7884
+ size?: number | undefined;
7885
+ }) => string | false;
7886
+ secondaryStorage: SecondaryStorage | undefined;
7887
+ password: {
7888
+ hash: (password: string) => Promise<string>;
7889
+ verify: (data: {
7890
+ password: string;
7891
+ hash: string;
7892
+ }) => Promise<boolean>;
7893
+ config: {
7894
+ minPasswordLength: number;
7895
+ maxPasswordLength: number;
7896
+ };
7897
+ checkPassword: (userId: string, ctx: GenericEndpointContext<BetterAuthOptions>) => Promise<boolean>;
7898
+ };
7899
+ tables: BetterAuthDBSchema;
7900
+ runMigrations: () => Promise<void>;
7901
+ publishTelemetry: (event: {
7902
+ type: string;
7903
+ anonymousId?: string | undefined;
7904
+ payload: Record<string, any>;
7905
+ }) => Promise<void>;
7906
+ skipOriginCheck: boolean;
7907
+ skipCSRFCheck: boolean;
7908
+ runInBackground: (promise: Promise<void>) => void;
7909
+ runInBackgroundOrAwait: (promise: Promise<unknown> | Promise<void> | void | unknown) => Promise<unknown>;
7811
7910
  }>) => Promise<R>): (inputContext: better_call0.MiddlewareInputContext<Options>) => Promise<R>;
7812
- <Options extends better_call0.MiddlewareOptions, R_1>(handler: (ctx: better_call0.MiddlewareContext<Options, AuthContext & {
7911
+ <Options extends better_call0.MiddlewareOptions, R_1>(handler: (ctx: better_call0.MiddlewareContext<Options, {
7813
7912
  returned?: unknown | undefined;
7814
7913
  responseHeaders?: Headers | undefined;
7914
+ } & PluginContext & {
7915
+ options: BetterAuthOptions;
7916
+ appName: string;
7917
+ baseURL: string;
7918
+ trustedOrigins: string[];
7919
+ isTrustedOrigin: (url: string, settings?: {
7920
+ allowRelativePaths: boolean;
7921
+ }) => boolean;
7922
+ oauthConfig: {
7923
+ skipStateCookieCheck?: boolean | undefined;
7924
+ storeStateStrategy: "database" | "cookie";
7925
+ };
7926
+ newSession: {
7927
+ session: Session & Record<string, any>;
7928
+ user: User & Record<string, any>;
7929
+ } | null;
7930
+ session: {
7931
+ session: Session & Record<string, any>;
7932
+ user: User & Record<string, any>;
7933
+ } | null;
7934
+ setNewSession: (session: {
7935
+ session: Session & Record<string, any>;
7936
+ user: User & Record<string, any>;
7937
+ } | null) => void;
7938
+ socialProviders: OAuthProvider[];
7939
+ authCookies: BetterAuthCookies;
7940
+ logger: ReturnType<typeof createLogger>;
7941
+ rateLimit: {
7942
+ enabled: boolean;
7943
+ window: number;
7944
+ max: number;
7945
+ storage: "memory" | "database" | "secondary-storage";
7946
+ } & BetterAuthRateLimitOptions;
7947
+ adapter: DBAdapter<BetterAuthOptions>;
7948
+ internalAdapter: InternalAdapter<BetterAuthOptions>;
7949
+ createAuthCookie: (cookieName: string, overrideAttributes?: Partial<better_call0.CookieOptions> | undefined) => {
7950
+ name: string;
7951
+ attributes: better_call0.CookieOptions;
7952
+ };
7953
+ secret: string;
7954
+ sessionConfig: {
7955
+ updateAge: number;
7956
+ expiresIn: number;
7957
+ freshAge: number;
7958
+ cookieRefreshCache: false | {
7959
+ enabled: true;
7960
+ updateAge: number;
7961
+ };
7962
+ };
7963
+ generateId: (options: {
7964
+ model: ModelNames;
7965
+ size?: number | undefined;
7966
+ }) => string | false;
7967
+ secondaryStorage: SecondaryStorage | undefined;
7968
+ password: {
7969
+ hash: (password: string) => Promise<string>;
7970
+ verify: (data: {
7971
+ password: string;
7972
+ hash: string;
7973
+ }) => Promise<boolean>;
7974
+ config: {
7975
+ minPasswordLength: number;
7976
+ maxPasswordLength: number;
7977
+ };
7978
+ checkPassword: (userId: string, ctx: GenericEndpointContext<BetterAuthOptions>) => Promise<boolean>;
7979
+ };
7980
+ tables: BetterAuthDBSchema;
7981
+ runMigrations: () => Promise<void>;
7982
+ publishTelemetry: (event: {
7983
+ type: string;
7984
+ anonymousId?: string | undefined;
7985
+ payload: Record<string, any>;
7986
+ }) => Promise<void>;
7987
+ skipOriginCheck: boolean;
7988
+ skipCSRFCheck: boolean;
7989
+ runInBackground: (promise: Promise<void>) => void;
7990
+ runInBackgroundOrAwait: (promise: Promise<unknown> | Promise<void> | void | unknown) => Promise<unknown>;
7815
7991
  }>) => Promise<R_1>): (inputContext: better_call0.MiddlewareInputContext<Options>) => Promise<R_1>;
7816
7992
  };
7817
7993
  type EndpointHandler<Path extends string, Options extends EndpointOptions, R> = (context: EndpointContext<Path, Options, AuthContext>) => Promise<R>;
@@ -7820,4 +7996,4 @@ declare function createAuthEndpoint<Path extends string, Options extends Endpoin
7820
7996
  type AuthEndpoint<Path extends string, Opts extends EndpointOptions, R> = ReturnType<typeof createAuthEndpoint<Path, Opts, R>>;
7821
7997
  type AuthMiddleware = ReturnType<typeof createAuthMiddleware>;
7822
7998
  //#endregion
7823
- export { AccountStatus as $, DBAdapterSchemaCreation as $n, GoogleProfile as $t, PolarOptions as A, getJwks as An, userSchema as Ar, linear as At, LineIdTokenPayload as B, createAuthorizationURL as Bn, BaseModelNames as Br, TwitchOptions as Bt, SocialProviderListEnum as C, atlassian as Cn, initGetFieldName as Cr, gitlab as Ct, VercelOptions as D, apple as Dn, Verification as Dr, LinearOptions as Dt, socialProviders as E, AppleProfile as En, initGetDefaultFieldName as Er, linkedin as Et, PayPalTokenResponse as F, validateToken as Fn, rateLimitSchema as Fr, DropboxProfile as Ft, NaverProfile as G, OAuthProvider as Gn, DBPrimitive as Gr, spotify as Gt, LineUserInfo as H, createClientCredentialsTokenRequest as Hn, DBFieldAttribute as Hr, twitch as Ht, paypal as I, generateCodeChallenge as In, Account as Ir, dropbox as It, KakaoProfile as J, CustomAdapter as Jn, slack as Jt, naver as K, ProviderOptions as Kn, ModelNames as Kr, SlackOptions as Kt, PaybinOptions as L, getOAuth2Tokens as Ln, accountSchema as Lr, TwitterOption as Lt, polar as M, verifyJwsAccessToken as Mn, Session as Mr, KickProfile as Mt, PayPalOptions as N, createAuthorizationCodeRequest as Nn, sessionSchema as Nr, kick as Nt, VercelProfile as O, getApplePublicKey as On, verificationSchema as Or, LinearProfile as Ot, PayPalProfile as P, validateAuthorizationCode as Pn, RateLimit as Pr, DropboxOptions as Pt, notion as Q, DBAdapterInstance as Qn, GoogleOptions as Qt, PaybinProfile as R, createRefreshAccessTokenRequest as Rn, BetterAuthPluginDBSchema as Rr, TwitterProfile as Rt, SocialProviderList as S, AtlassianProfile as Sn, initGetIdField as Sr, GitlabProfile as St, socialProviderList as T, AppleOptions as Tn, initGetDefaultModelName as Tr, LinkedInProfile as Tt, line as U, OAuth2Tokens as Un, DBFieldAttributeConfig as Ur, SpotifyOptions as Ut, LineOptions as V, clientCredentialsToken as Vn, BetterAuthDBSchema as Vr, TwitchProfile as Vt, NaverOptions as W, OAuth2UserInfo as Wn, DBFieldType as Wr, SpotifyProfile as Wt, NotionOptions as X, DBAdapterDebugLogOption as Xn, HuggingFaceProfile as Xt, kakao as Y, DBAdapter as Yn, HuggingFaceOptions as Yt, NotionProfile as Z, DBAdapterFactoryConfig as Zn, huggingface as Zt, BetterAuthRateLimitOptions as _, CognitoOptions as _n, LiteralString as _r, reddit as _t, optionsMiddleware as a, GithubOptions as an, withApplyDefault as ar, zoom as at, HookEndpointContext as b, getCognitoPublicKey as bn, Primitive as br, tiktok as bt, BetterAuthClientPlugin as c, FigmaOptions as cn, createAdapterFactory as cr, vk as ct, ClientStore as d, FacebookOptions as dn, AdapterFactoryCustomizeAdapterCreator as dr, salesforce as dt, getGooglePublicKey as en, DBTransactionAdapter as er, LoginType as et, AuthContext as f, FacebookProfile as fn, AdapterFactoryOptions as fr, RobloxOptions as ft, BetterAuthOptions as g, discord as gn, Awaitable as gr, RedditProfile as gt, BetterAuthAdvancedOptions as h, DiscordProfile as hn, CreateCustomAdapter as hr, RedditOptions as ht, createAuthMiddleware as i, microsoft as in, deepmerge as ir, ZoomProfile as it, PolarProfile as j, verifyAccessToken as jn, coreSchema as jr, KickOptions as jt, vercel as k, BetterAuthCookies as kn, User as kr, LinearUser as kt, ClientAtomListener as l, FigmaProfile as ln, AdapterConfig as lr, SalesforceOptions as lt, InternalAdapter as m, DiscordOptions as mn, CreateAdapterOptions as mr, roblox as mt, AuthMiddleware as n, MicrosoftEntraIDProfile as nn, JoinOption as nr, PronounOption as nt, StandardSchemaV1$1 as o, GithubProfile as on, AdapterFactory as or, VkOption as ot, GenericEndpointContext as p, facebook as pn, AdapterTestDebugLogs as pr, RobloxProfile as pt, KakaoOptions as q, CleanedWhere as qn, SecondaryStorage as qr, SlackProfile as qt, createAuthEndpoint as r, MicrosoftOptions as rn, Where as rr, ZoomOptions as rt, BetterAuthClientOptions as s, github as sn, createAdapter as sr, VkProfile as st, AuthEndpoint as t, google as tn, JoinConfig as tr, PhoneNumber as tt, ClientFetchOption as u, figma as un, AdapterFactoryConfig as ur, SalesforceProfile as ut, GenerateIdFn as v, CognitoProfile as vn, LiteralUnion as vr, TiktokOptions as vt, SocialProviders as w, AppleNonConformUser as wn, initGetFieldAttributes as wr, LinkedInOptions as wt, SocialProvider as x, AtlassianOptions as xn, initGetModelName as xr, GitlabOptions as xt, BetterAuthPlugin as y, cognito as yn, Prettify as yr, TiktokProfile as yt, paybin as z, refreshAccessToken as zn, getAuthTables as zr, twitter as zt };
7999
+ export { notion as $, DBAdapterInstance as $n, GoogleOptions as $t, vercel as A, BetterAuthCookies as An, User as Ar, LinearUser as At, paybin as B, refreshAccessToken as Bn, getAuthTables as Br, twitter as Bt, SocialProviderList as C, AtlassianProfile as Cn, initGetIdField as Cr, GitlabProfile as Ct, socialProviders as D, AppleProfile as Dn, initGetDefaultFieldName as Dr, linkedin as Dt, socialProviderList as E, AppleOptions as En, initGetDefaultModelName as Er, LinkedInProfile as Et, PayPalProfile as F, validateAuthorizationCode as Fn, RateLimit as Fr, DropboxOptions as Ft, NaverOptions as G, OAuth2UserInfo as Gn, DBFieldType as Gr, SpotifyProfile as Gt, LineOptions as H, clientCredentialsToken as Hn, BetterAuthDBSchema as Hr, TwitchProfile as Ht, PayPalTokenResponse as I, validateToken as In, rateLimitSchema as Ir, DropboxProfile as It, KakaoOptions as J, CleanedWhere as Jn, SecondaryStorage as Jr, SlackProfile as Jt, NaverProfile as K, OAuthProvider as Kn, DBPrimitive as Kr, spotify as Kt, paypal as L, generateCodeChallenge as Ln, Account as Lr, dropbox as Lt, PolarProfile as M, verifyAccessToken as Mn, coreSchema as Mr, KickOptions as Mt, polar as N, verifyJwsAccessToken as Nn, Session as Nr, KickProfile as Nt, VercelOptions as O, apple as On, Verification as Or, LinearOptions as Ot, PayPalOptions as P, createAuthorizationCodeRequest as Pn, sessionSchema as Pr, kick as Pt, NotionProfile as Q, DBAdapterFactoryConfig as Qn, huggingface as Qt, PaybinOptions as R, getOAuth2Tokens as Rn, accountSchema as Rr, TwitterOption as Rt, SocialProvider as S, AtlassianOptions as Sn, initGetModelName as Sr, GitlabOptions as St, SocialProviders as T, AppleNonConformUser as Tn, initGetFieldAttributes as Tr, LinkedInOptions as Tt, LineUserInfo as U, createClientCredentialsTokenRequest as Un, DBFieldAttribute as Ur, twitch as Ut, LineIdTokenPayload as V, createAuthorizationURL as Vn, BaseModelNames as Vr, TwitchOptions as Vt, line as W, OAuth2Tokens as Wn, DBFieldAttributeConfig as Wr, SpotifyOptions as Wt, kakao as X, DBAdapter as Xn, HuggingFaceOptions as Xt, KakaoProfile as Y, CustomAdapter as Yn, slack as Yt, NotionOptions as Z, DBAdapterDebugLogOption as Zn, HuggingFaceProfile as Zt, BetterAuthOptions as _, discord as _n, Awaitable as _r, RedditProfile as _t, optionsMiddleware as a, microsoft as an, deepmerge as ar, ZoomProfile as at, BetterAuthPlugin as b, cognito as bn, Prettify as br, TiktokProfile as bt, BetterAuthClientPlugin as c, github as cn, createAdapter as cr, VkProfile as ct, ClientStore as d, figma as dn, AdapterFactoryConfig as dr, SalesforceProfile as dt, GoogleProfile as en, DBAdapterSchemaCreation as er, AccountStatus as et, AuthContext as f, FacebookOptions as fn, AdapterFactoryCustomizeAdapterCreator as fr, salesforce as ft, BetterAuthAdvancedOptions as g, DiscordProfile as gn, CreateCustomAdapter as gr, RedditOptions as gt, PluginContext as h, DiscordOptions as hn, CreateAdapterOptions as hr, roblox as ht, createAuthMiddleware as i, MicrosoftOptions as in, Where as ir, ZoomOptions as it, PolarOptions as j, getJwks as jn, userSchema as jr, linear as jt, VercelProfile as k, getApplePublicKey as kn, verificationSchema as kr, LinearProfile as kt, ClientAtomListener as l, FigmaOptions as ln, createAdapterFactory as lr, vk as lt, InternalAdapter as m, facebook as mn, AdapterTestDebugLogs as mr, RobloxProfile as mt, AuthMiddleware as n, google as nn, JoinConfig as nr, PhoneNumber as nt, StandardSchemaV1$1 as o, GithubOptions as on, withApplyDefault as or, zoom as ot, GenericEndpointContext as p, FacebookProfile as pn, AdapterFactoryOptions as pr, RobloxOptions as pt, naver as q, ProviderOptions as qn, ModelNames as qr, SlackOptions as qt, createAuthEndpoint as r, MicrosoftEntraIDProfile as rn, JoinOption as rr, PronounOption as rt, BetterAuthClientOptions as s, GithubProfile as sn, AdapterFactory as sr, VkOption as st, AuthEndpoint as t, getGooglePublicKey as tn, DBTransactionAdapter as tr, LoginType as tt, ClientFetchOption as u, FigmaProfile as un, AdapterConfig as ur, SalesforceOptions as ut, BetterAuthRateLimitOptions as v, CognitoOptions as vn, LiteralString as vr, reddit as vt, SocialProviderListEnum as w, atlassian as wn, initGetFieldName as wr, gitlab as wt, HookEndpointContext as x, getCognitoPublicKey as xn, Primitive as xr, tiktok as xt, GenerateIdFn as y, CognitoProfile as yn, LiteralUnion as yr, TiktokOptions as yt, PaybinProfile as z, createRefreshAccessTokenRequest as zn, BetterAuthPluginDBSchema as zr, TwitterProfile as zt };
package/dist/index.d.mts CHANGED
@@ -1,2 +1,2 @@
1
- import { _ as BetterAuthRateLimitOptions, _r as LiteralString, b as HookEndpointContext, br as Primitive, c as BetterAuthClientPlugin, d as ClientStore, f as AuthContext, g as BetterAuthOptions, gr as Awaitable, h as BetterAuthAdvancedOptions, kn as BetterAuthCookies, l as ClientAtomListener, m as InternalAdapter, o as StandardSchemaV1, p as GenericEndpointContext, s as BetterAuthClientOptions, u as ClientFetchOption, v as GenerateIdFn, vr as LiteralUnion, y as BetterAuthPlugin, yr as Prettify } from "./index-1XS3AkXa.mjs";
2
- export { AuthContext, Awaitable, BetterAuthAdvancedOptions, BetterAuthClientOptions, BetterAuthClientPlugin, BetterAuthCookies, BetterAuthOptions, BetterAuthPlugin, BetterAuthRateLimitOptions, ClientAtomListener, ClientFetchOption, ClientStore, GenerateIdFn, GenericEndpointContext, HookEndpointContext, InternalAdapter, LiteralString, LiteralUnion, Prettify, Primitive, StandardSchemaV1 };
1
+ import { An as BetterAuthCookies, _ as BetterAuthOptions, _r as Awaitable, b as BetterAuthPlugin, br as Prettify, c as BetterAuthClientPlugin, d as ClientStore, f as AuthContext, g as BetterAuthAdvancedOptions, h as PluginContext, l as ClientAtomListener, m as InternalAdapter, o as StandardSchemaV1, p as GenericEndpointContext, s as BetterAuthClientOptions, u as ClientFetchOption, v as BetterAuthRateLimitOptions, vr as LiteralString, x as HookEndpointContext, xr as Primitive, y as GenerateIdFn, yr as LiteralUnion } from "./index-eRGNbXt_.mjs";
2
+ export { AuthContext, Awaitable, BetterAuthAdvancedOptions, BetterAuthClientOptions, BetterAuthClientPlugin, BetterAuthCookies, BetterAuthOptions, BetterAuthPlugin, BetterAuthRateLimitOptions, ClientAtomListener, ClientFetchOption, ClientStore, GenerateIdFn, GenericEndpointContext, HookEndpointContext, InternalAdapter, LiteralString, LiteralUnion, PluginContext, Prettify, Primitive, StandardSchemaV1 };
@@ -1,2 +1,2 @@
1
- import { An as getJwks, Bn as createAuthorizationURL, Fn as validateToken, Gn as OAuthProvider, Hn as createClientCredentialsTokenRequest, In as generateCodeChallenge, Kn as ProviderOptions, Ln as getOAuth2Tokens, Mn as verifyJwsAccessToken, Nn as createAuthorizationCodeRequest, Pn as validateAuthorizationCode, Rn as createRefreshAccessTokenRequest, Un as OAuth2Tokens, Vn as clientCredentialsToken, Wn as OAuth2UserInfo, jn as verifyAccessToken, zn as refreshAccessToken } from "../index-1XS3AkXa.mjs";
1
+ import { Bn as refreshAccessToken, Fn as validateAuthorizationCode, Gn as OAuth2UserInfo, Hn as clientCredentialsToken, In as validateToken, Kn as OAuthProvider, Ln as generateCodeChallenge, Mn as verifyAccessToken, Nn as verifyJwsAccessToken, Pn as createAuthorizationCodeRequest, Rn as getOAuth2Tokens, Un as createClientCredentialsTokenRequest, Vn as createAuthorizationURL, Wn as OAuth2Tokens, jn as getJwks, qn as ProviderOptions, zn as createRefreshAccessTokenRequest } from "../index-eRGNbXt_.mjs";
2
2
  export { OAuth2Tokens, OAuth2UserInfo, OAuthProvider, ProviderOptions, clientCredentialsToken, createAuthorizationCodeRequest, createAuthorizationURL, createClientCredentialsTokenRequest, createRefreshAccessTokenRequest, generateCodeChallenge, getJwks, getOAuth2Tokens, refreshAccessToken, validateAuthorizationCode, validateToken, verifyAccessToken, verifyJwsAccessToken };
@@ -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-1XS3AkXa.mjs";
1
+ import { $ as notion, $t as GoogleOptions, A as vercel, At as LinearUser, B as paybin, Bt as twitter, C as SocialProviderList, Cn as AtlassianProfile, Ct as GitlabProfile, D as socialProviders, Dn as AppleProfile, Dt as linkedin, E as socialProviderList, En as AppleOptions, Et as LinkedInProfile, F as PayPalProfile, Ft as DropboxOptions, G as NaverOptions, Gt as SpotifyProfile, H as LineOptions, Ht as TwitchProfile, I as PayPalTokenResponse, It as DropboxProfile, J as KakaoOptions, Jt as SlackProfile, K as NaverProfile, Kt as spotify, L as paypal, Lt as dropbox, M as PolarProfile, Mt as KickOptions, N as polar, Nt as KickProfile, O as VercelOptions, On as apple, Ot as LinearOptions, P as PayPalOptions, Pt as kick, Q as NotionProfile, Qt as huggingface, R as PaybinOptions, Rt as TwitterOption, S as SocialProvider, Sn as AtlassianOptions, St as GitlabOptions, T as SocialProviders, Tn as AppleNonConformUser, Tt as LinkedInOptions, U as LineUserInfo, Ut as twitch, V as LineIdTokenPayload, Vt as TwitchOptions, W as line, Wt as SpotifyOptions, X as kakao, Xt as HuggingFaceOptions, Y as KakaoProfile, Yt as slack, Z as NotionOptions, Zt as HuggingFaceProfile, _n as discord, _t as RedditProfile, an as microsoft, at as ZoomProfile, bn as cognito, bt as TiktokProfile, cn as github, ct as VkProfile, dn as figma, dt as SalesforceProfile, en as GoogleProfile, et as AccountStatus, fn as FacebookOptions, ft as salesforce, gn as DiscordProfile, gt as RedditOptions, hn as DiscordOptions, ht as roblox, in as MicrosoftOptions, it as ZoomOptions, j as PolarOptions, jt as linear, k as VercelProfile, kn as getApplePublicKey, kt as LinearProfile, ln as FigmaOptions, lt as vk, mn as facebook, mt as RobloxProfile, nn as google, nt as PhoneNumber, on as GithubOptions, ot as zoom, pn as FacebookProfile, pt as RobloxOptions, q as naver, qt as SlackOptions, rn as MicrosoftEntraIDProfile, rt as PronounOption, sn as GithubProfile, st as VkOption, tn as getGooglePublicKey, tt as LoginType, un as FigmaProfile, ut as SalesforceOptions, vn as CognitoOptions, vt as reddit, w as SocialProviderListEnum, wn as atlassian, wt as gitlab, xn as getCognitoPublicKey, xt as tiktok, yn as CognitoProfile, yt as TiktokOptions, z as PaybinProfile, zt as TwitterProfile } from "../index-eRGNbXt_.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,6 +1,6 @@
1
1
  import { i as logger } from "../env-DbssmzoK.mjs";
2
- import "../utils-NloIXYE0.mjs";
3
- import { t as BetterAuthError } from "../error-RtKwr3Pu.mjs";
2
+ import "../utils-U2L7n92V.mjs";
3
+ import { t as BetterAuthError } from "../error-DP1xOn7P.mjs";
4
4
  import { a as validateAuthorizationCode, c as refreshAccessToken, d as getOAuth2Tokens, l as createAuthorizationURL, u as generateCodeChallenge } from "../oauth2-BjWM15hm.mjs";
5
5
  import * as z from "zod";
6
6
  import { base64 } from "@better-auth/utils/base64";
@@ -1,3 +1,12 @@
1
+ import { t as InternalLogger } from "../index-BRBu0-5h.mjs";
2
+
3
+ //#region src/utils/deprecate.d.ts
4
+
5
+ /**
6
+ * Wraps a function to log a deprecation warning at once.
7
+ */
8
+ declare function deprecate<T extends (...args: any[]) => any>(fn: T, message: string, logger?: InternalLogger): T;
9
+ //#endregion
1
10
  //#region src/utils/error-codes.d.ts
2
11
  type UpperLetter = "A" | "B" | "C" | "D" | "E" | "F" | "G" | "H" | "I" | "J" | "K" | "L" | "M" | "N" | "O" | "P" | "Q" | "R" | "S" | "T" | "U" | "V" | "W" | "X" | "Y" | "Z";
3
12
  type SpecialCharacter = "_";
@@ -15,4 +24,4 @@ declare function safeJSONParse<T>(data: unknown): T | null;
15
24
  //#region src/utils/string.d.ts
16
25
  declare function capitalizeFirstLetter(str: string): string;
17
26
  //#endregion
18
- export { capitalizeFirstLetter, defineErrorCodes, generateId, safeJSONParse };
27
+ export { capitalizeFirstLetter, defineErrorCodes, deprecate, generateId, safeJSONParse };
@@ -1,4 +1,4 @@
1
1
  import "../env-DbssmzoK.mjs";
2
- import { i as defineErrorCodes, n as safeJSONParse, r as generateId, t as capitalizeFirstLetter } from "../utils-NloIXYE0.mjs";
2
+ import { a as deprecate, i as defineErrorCodes, n as safeJSONParse, r as generateId, t as capitalizeFirstLetter } from "../utils-U2L7n92V.mjs";
3
3
 
4
- export { capitalizeFirstLetter, defineErrorCodes, generateId, safeJSONParse };
4
+ export { capitalizeFirstLetter, defineErrorCodes, deprecate, generateId, safeJSONParse };
@@ -1,6 +1,22 @@
1
1
  import { i as logger } from "./env-DbssmzoK.mjs";
2
2
  import { createRandomStringGenerator } from "@better-auth/utils/random";
3
3
 
4
+ //#region src/utils/deprecate.ts
5
+ /**
6
+ * Wraps a function to log a deprecation warning at once.
7
+ */
8
+ function deprecate(fn, message, logger$1) {
9
+ let warned = false;
10
+ return function(...args) {
11
+ if (!warned) {
12
+ (logger$1?.warn ?? console.warn)(`[Deprecation] ${message}`);
13
+ warned = true;
14
+ }
15
+ return fn.apply(this, args);
16
+ };
17
+ }
18
+
19
+ //#endregion
4
20
  //#region src/utils/error-codes.ts
5
21
  function defineErrorCodes(codes) {
6
22
  return codes;
@@ -40,4 +56,4 @@ function capitalizeFirstLetter(str) {
40
56
  }
41
57
 
42
58
  //#endregion
43
- export { defineErrorCodes as i, safeJSONParse as n, generateId as r, capitalizeFirstLetter as t };
59
+ export { deprecate as a, defineErrorCodes as i, safeJSONParse as n, generateId as r, capitalizeFirstLetter as t };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@better-auth/core",
3
- "version": "1.4.10",
3
+ "version": "1.4.11-beta.2",
4
4
  "description": "The most comprehensive authentication framework for TypeScript.",
5
5
  "type": "module",
6
6
  "repository": {
@@ -19,3 +19,32 @@ export {
19
19
  runWithAdapter,
20
20
  runWithTransaction,
21
21
  } from "./transaction";
22
+
23
+ const glo: any =
24
+ typeof globalThis !== "undefined"
25
+ ? globalThis
26
+ : typeof window !== "undefined"
27
+ ? window
28
+ : typeof global !== "undefined"
29
+ ? global
30
+ : {};
31
+
32
+ const importIdentifier = "__ $BETTER_AUTH$ __";
33
+
34
+ if (glo[importIdentifier] === true) {
35
+ /**
36
+ * Dear reader of this message. Please take this seriously.
37
+ *
38
+ * If you see this message, make sure that you only import one version of Better Auth. In many cases,
39
+ * your package manager installs two versions of Better Auth that are used by different packages within your project.
40
+ *
41
+ * This often leads to issues that are hard to debug. We often need to ensure async local storage instance,
42
+ * If you imported different versions of Better Auth, it is impossible for us to
43
+ * do status synchronization per request anymore - which might break the states.
44
+ *
45
+ */
46
+ console.error(
47
+ "Better Auth was already imported. This breaks async local storage instance and will lead to issues!",
48
+ );
49
+ }
50
+ glo[importIdentifier] = true;
@@ -16,6 +16,7 @@ import type {
16
16
  BetterAuthOptions,
17
17
  BetterAuthRateLimitOptions,
18
18
  } from "./init-options";
19
+ import type { BetterAuthPlugin } from "./plugin";
19
20
 
20
21
  export type GenericEndpointContext<
21
22
  Options extends BetterAuthOptions = BetterAuthOptions,
@@ -159,8 +160,14 @@ type CheckPasswordFn<Options extends BetterAuthOptions = BetterAuthOptions> = (
159
160
  ctx: GenericEndpointContext<Options>,
160
161
  ) => Promise<boolean>;
161
162
 
163
+ export type PluginContext = {
164
+ getPlugin: <Plugin extends BetterAuthPlugin>(
165
+ pluginId: Plugin["id"],
166
+ ) => Plugin | null;
167
+ };
168
+
162
169
  export type AuthContext<Options extends BetterAuthOptions = BetterAuthOptions> =
163
- {
170
+ PluginContext & {
164
171
  options: Options;
165
172
  appName: string;
166
173
  baseURL: string;
@@ -3,6 +3,7 @@ export type {
3
3
  AuthContext,
4
4
  GenericEndpointContext,
5
5
  InternalAdapter,
6
+ PluginContext,
6
7
  } from "./context";
7
8
  export type { BetterAuthCookies } from "./cookie";
8
9
  export type * from "./helper";
@@ -478,8 +478,18 @@ export type BetterAuthOptions = {
478
478
  * A function that is called when a user verifies their email
479
479
  * @param user the user that verified their email
480
480
  * @param request the request object
481
+ * @deprecated Use `beforeEmailVerification` or `afterEmailVerification` instead. This will be removed in 1.5
481
482
  */
482
483
  onEmailVerification?: (user: User, request?: Request) => Promise<void>;
484
+ /**
485
+ * A function that is called before a user verifies their email
486
+ * @param user the user that verified their email
487
+ * @param request the request object
488
+ */
489
+ beforeEmailVerification?: (
490
+ user: User,
491
+ request?: Request,
492
+ ) => Promise<void>;
483
493
  /**
484
494
  * A function that is called when a user's email is updated to verified
485
495
  * @param user the user that verified their email
@@ -1002,9 +1012,26 @@ export type BetterAuthOptions = {
1002
1012
  *
1003
1013
  * Trusted origins will be dynamically
1004
1014
  * calculated based on the request.
1015
+ *
1016
+ * @example
1017
+ * ```ts
1018
+ * trustedOrigins: async (request) => {
1019
+ * return [
1020
+ * "https://better-auth.com",
1021
+ * "https://*.better-auth.com",
1022
+ * request.headers.get("x-custom-origin")
1023
+ * ];
1024
+ * }
1025
+ * ```
1026
+ * @returns An array of trusted origins.
1005
1027
  */
1006
1028
  trustedOrigins?:
1007
- | (string[] | ((request?: Request | undefined) => Awaitable<string[]>))
1029
+ | (
1030
+ | string[]
1031
+ | ((
1032
+ request?: Request | undefined,
1033
+ ) => Awaitable<(string | undefined | null)[]>)
1034
+ )
1008
1035
  | undefined;
1009
1036
  /**
1010
1037
  * Rate limiting configuration
@@ -0,0 +1,72 @@
1
+ import { describe, expect, it, vi } from "vitest";
2
+ import { deprecate } from "./deprecate";
3
+
4
+ describe("deprecate", () => {
5
+ it("should warn once when called multiple times", () => {
6
+ const warn = vi.fn();
7
+ const logger = { warn } as any;
8
+ const fn = vi.fn();
9
+ const deprecatedFn = deprecate(fn, "test message", logger);
10
+
11
+ deprecatedFn();
12
+ deprecatedFn();
13
+ deprecatedFn();
14
+
15
+ expect(warn).toHaveBeenCalledTimes(1);
16
+ expect(warn).toHaveBeenCalledWith("[Deprecation] test message");
17
+ expect(fn).toHaveBeenCalledTimes(3);
18
+ });
19
+
20
+ it("should use provided logger if available", () => {
21
+ const warn = vi.fn();
22
+ const logger = { warn } as any;
23
+ const fn = vi.fn();
24
+ const deprecatedFn = deprecate(fn, "test message", logger);
25
+
26
+ deprecatedFn();
27
+
28
+ expect(warn).toHaveBeenCalledWith("[Deprecation] test message");
29
+ });
30
+
31
+ it("should fall back to console.warn if no logger provided", () => {
32
+ const consoleWarn = vi.spyOn(console, "warn").mockImplementation(() => {});
33
+ const fn = vi.fn();
34
+ const deprecatedFn = deprecate(fn, "test message");
35
+
36
+ deprecatedFn();
37
+
38
+ expect(consoleWarn).toHaveBeenCalledWith("[Deprecation] test message");
39
+ consoleWarn.mockRestore();
40
+ });
41
+
42
+ it("should pass arguments and return value correctly", () => {
43
+ const fn = vi.fn((a: number, b: number) => a + b);
44
+ const deprecatedFn = deprecate(fn, "test message", {
45
+ warn: vi.fn(),
46
+ } as any);
47
+
48
+ const result = deprecatedFn(1, 2);
49
+
50
+ expect(result).toBe(3);
51
+ expect(fn).toHaveBeenCalledWith(1, 2);
52
+ });
53
+
54
+ it("should preserve this context", () => {
55
+ class TestClass {
56
+ value = 10;
57
+ method(a: number) {
58
+ return this.value + a;
59
+ }
60
+ }
61
+
62
+ const instance = new TestClass();
63
+ const originalMethod = instance.method;
64
+ instance.method = deprecate(originalMethod, "test message", {
65
+ warn: vi.fn(),
66
+ } as any);
67
+
68
+ const result = instance.method(5);
69
+
70
+ expect(result).toBe(15);
71
+ });
72
+ });
@@ -0,0 +1,21 @@
1
+ import type { InternalLogger } from "../env";
2
+
3
+ /**
4
+ * Wraps a function to log a deprecation warning at once.
5
+ */
6
+ export function deprecate<T extends (...args: any[]) => any>(
7
+ fn: T,
8
+ message: string,
9
+ logger?: InternalLogger,
10
+ ): T {
11
+ let warned = false;
12
+
13
+ return function (this: any, ...args: Parameters<T>): ReturnType<T> {
14
+ if (!warned) {
15
+ const warn = logger?.warn ?? console.warn;
16
+ warn(`[Deprecation] ${message}`);
17
+ warned = true;
18
+ }
19
+ return fn.apply(this, args);
20
+ } as T;
21
+ }
@@ -1,3 +1,4 @@
1
+ export { deprecate } from "./deprecate";
1
2
  export { defineErrorCodes } from "./error-codes";
2
3
  export { generateId } from "./id";
3
4
  export { safeJSONParse } from "./json";