@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.
- package/.turbo/turbo-build.log +11 -11
- package/dist/api/index.d.mts +1 -1
- package/dist/api/index.mjs +1 -1
- package/dist/context/index.d.mts +1 -1
- package/dist/context/index.mjs +1 -1
- package/dist/{context-DblZrIwO.mjs → context-BBNwughv.mjs} +19 -0
- package/dist/db/adapter/index.d.mts +1 -1
- package/dist/db/adapter/index.mjs +2 -2
- package/dist/db/index.d.mts +1 -1
- package/dist/error/index.mjs +2 -2
- package/dist/{error-RtKwr3Pu.mjs → error-DP1xOn7P.mjs} +1 -1
- package/dist/{index-1XS3AkXa.d.mts → index-eRGNbXt_.d.mts} +181 -5
- package/dist/index.d.mts +2 -2
- package/dist/oauth2/index.d.mts +1 -1
- package/dist/social-providers/index.d.mts +1 -1
- package/dist/social-providers/index.mjs +2 -2
- package/dist/utils/index.d.mts +10 -1
- package/dist/utils/index.mjs +2 -2
- package/dist/{utils-NloIXYE0.mjs → utils-U2L7n92V.mjs} +17 -1
- package/package.json +1 -1
- package/src/context/index.ts +29 -0
- package/src/types/context.ts +8 -1
- package/src/types/index.ts +1 -0
- package/src/types/init-options.ts +28 -1
- package/src/utils/deprecate.test.ts +72 -0
- package/src/utils/deprecate.ts +21 -0
- package/src/utils/index.ts +1 -0
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
> @better-auth/core@1.4.
|
|
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
|
[34mℹ[39m tsdown [2mv0.17.2[22m powered by rolldown [2mv1.0.0-beta.53[22m
|
|
@@ -16,28 +16,28 @@
|
|
|
16
16
|
[34mℹ[39m [2mdist/[22m[1moauth2/index.mjs[22m [2m 0.75 kB[22m [2m│ gzip: 0.28 kB[22m
|
|
17
17
|
[34mℹ[39m [2mdist/[22m[1mcontext/index.mjs[22m [2m 0.70 kB[22m [2m│ gzip: 0.24 kB[22m
|
|
18
18
|
[34mℹ[39m [2mdist/[22m[1menv/index.mjs[22m [2m 0.44 kB[22m [2m│ gzip: 0.25 kB[22m
|
|
19
|
-
[34mℹ[39m [2mdist/[22m[1mutils/index.mjs[22m [2m 0.
|
|
19
|
+
[34mℹ[39m [2mdist/[22m[1mutils/index.mjs[22m [2m 0.26 kB[22m [2m│ gzip: 0.18 kB[22m
|
|
20
20
|
[34mℹ[39m [2mdist/[22m[1merror/index.mjs[22m [2m 0.19 kB[22m [2m│ gzip: 0.14 kB[22m
|
|
21
21
|
[34mℹ[39m [2mdist/[22m[1mindex.mjs[22m [2m 0.01 kB[22m [2m│ gzip: 0.03 kB[22m
|
|
22
22
|
[34mℹ[39m [2mdist/[22moauth2-BjWM15hm.mjs [2m 12.82 kB[22m [2m│ gzip: 3.16 kB[22m
|
|
23
23
|
[34mℹ[39m [2mdist/[22menv-DbssmzoK.mjs [2m 7.67 kB[22m [2m│ gzip: 2.54 kB[22m
|
|
24
24
|
[34mℹ[39m [2mdist/[22mget-tables-CMc_Emww.mjs [2m 6.76 kB[22m [2m│ gzip: 1.30 kB[22m
|
|
25
|
-
[34mℹ[39m [2mdist/[22mcontext-
|
|
26
|
-
[34mℹ[39m [2mdist/[22merror-
|
|
27
|
-
[34mℹ[39m [2mdist/[22mutils-
|
|
28
|
-
[34mℹ[39m [2mdist/[22m[32m[1msocial-providers/index.d.mts[22m[39m [2m 3.
|
|
25
|
+
[34mℹ[39m [2mdist/[22mcontext-BBNwughv.mjs [2m 4.87 kB[22m [2m│ gzip: 1.40 kB[22m
|
|
26
|
+
[34mℹ[39m [2mdist/[22merror-DP1xOn7P.mjs [2m 2.76 kB[22m [2m│ gzip: 1.16 kB[22m
|
|
27
|
+
[34mℹ[39m [2mdist/[22mutils-U2L7n92V.mjs [2m 1.46 kB[22m [2m│ gzip: 0.70 kB[22m
|
|
28
|
+
[34mℹ[39m [2mdist/[22m[32m[1msocial-providers/index.d.mts[22m[39m [2m 3.89 kB[22m [2m│ gzip: 1.19 kB[22m
|
|
29
29
|
[34mℹ[39m [2mdist/[22m[32m[1mcontext/index.d.mts[22m[39m [2m 3.02 kB[22m [2m│ gzip: 0.96 kB[22m
|
|
30
30
|
[34mℹ[39m [2mdist/[22m[32m[1merror/index.d.mts[22m[39m [2m 3.02 kB[22m [2m│ gzip: 1.10 kB[22m
|
|
31
|
+
[34mℹ[39m [2mdist/[22m[32m[1mutils/index.d.mts[22m[39m [2m 1.50 kB[22m [2m│ gzip: 0.68 kB[22m
|
|
31
32
|
[34mℹ[39m [2mdist/[22m[32m[1mdb/adapter/index.d.mts[22m[39m [2m 1.34 kB[22m [2m│ gzip: 0.43 kB[22m
|
|
32
|
-
[34mℹ[39m [2mdist/[22m[32m[
|
|
33
|
-
[34mℹ[39m [2mdist/[22m[32m[1mindex.d.mts[22m[39m [2m 0.92 kB[22m [2m│ gzip: 0.35 kB[22m
|
|
33
|
+
[34mℹ[39m [2mdist/[22m[32m[1mindex.d.mts[22m[39m [2m 0.95 kB[22m [2m│ gzip: 0.36 kB[22m
|
|
34
34
|
[34mℹ[39m [2mdist/[22m[32m[1moauth2/index.d.mts[22m[39m [2m 0.88 kB[22m [2m│ gzip: 0.32 kB[22m
|
|
35
35
|
[34mℹ[39m [2mdist/[22m[32m[1mdb/index.d.mts[22m[39m [2m 0.81 kB[22m [2m│ gzip: 0.34 kB[22m
|
|
36
36
|
[34mℹ[39m [2mdist/[22m[32m[1menv/index.d.mts[22m[39m [2m 0.59 kB[22m [2m│ gzip: 0.30 kB[22m
|
|
37
37
|
[34mℹ[39m [2mdist/[22m[32m[1mapi/index.d.mts[22m[39m [2m 0.26 kB[22m [2m│ gzip: 0.14 kB[22m
|
|
38
38
|
[34mℹ[39m [2mdist/[22m[32m[1masync_hooks/index.d.mts[22m[39m [2m 0.24 kB[22m [2m│ gzip: 0.16 kB[22m
|
|
39
39
|
[34mℹ[39m [2mdist/[22m[32m[1masync_hooks/pure.index.d.mts[22m[39m [2m 0.22 kB[22m [2m│ gzip: 0.16 kB[22m
|
|
40
|
-
[34mℹ[39m [2mdist/[22m[32mindex-
|
|
40
|
+
[34mℹ[39m [2mdist/[22m[32mindex-eRGNbXt_.d.mts[39m [2m227.31 kB[22m [2m│ gzip: 35.80 kB[22m
|
|
41
41
|
[34mℹ[39m [2mdist/[22m[32mindex-BRBu0-5h.d.mts[39m [2m 3.31 kB[22m [2m│ gzip: 1.11 kB[22m
|
|
42
|
-
[34mℹ[39m 32 files, total:
|
|
43
|
-
[32m✔[39m Build complete in [
|
|
42
|
+
[34mℹ[39m 32 files, total: 410.48 kB
|
|
43
|
+
[32m✔[39m Build complete in [32m5228ms[39m
|
package/dist/api/index.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as optionsMiddleware, i as createAuthMiddleware, n as AuthMiddleware, r as createAuthEndpoint, t as AuthEndpoint } from "../index-
|
|
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 };
|
package/dist/api/index.mjs
CHANGED
package/dist/context/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
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
|
|
package/dist/context/index.mjs
CHANGED
|
@@ -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-
|
|
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
|
|
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-
|
|
4
|
-
import { t as BetterAuthError } from "../../error-
|
|
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 }) => {
|
package/dist/db/index.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { Ar as
|
|
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 };
|
package/dist/error/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import "../env-DbssmzoK.mjs";
|
|
2
|
-
import "../utils-
|
|
3
|
-
import { n as BASE_ERROR_CODES, t as BetterAuthError } from "../error-
|
|
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 };
|
|
@@ -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
|
|
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,
|
|
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,
|
|
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 {
|
|
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
|
|
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 };
|
package/dist/oauth2/index.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
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
|
|
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-
|
|
3
|
-
import { t as BetterAuthError } from "../error-
|
|
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";
|
package/dist/utils/index.d.mts
CHANGED
|
@@ -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 };
|
package/dist/utils/index.mjs
CHANGED
|
@@ -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-
|
|
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
package/src/context/index.ts
CHANGED
|
@@ -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;
|
package/src/types/context.ts
CHANGED
|
@@ -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;
|
package/src/types/index.ts
CHANGED
|
@@ -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
|
-
| (
|
|
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
|
+
}
|
package/src/utils/index.ts
CHANGED