@better-auth/core 1.3.26 → 1.4.0-beta.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (138) hide show
  1. package/.turbo/turbo-build.log +72 -24
  2. package/dist/async_hooks/index.cjs +12 -20
  3. package/dist/async_hooks/index.d.cts +4 -7
  4. package/dist/async_hooks/index.d.ts +4 -7
  5. package/dist/async_hooks/index.js +18 -0
  6. package/dist/chunk-CUT6urMc.cjs +30 -0
  7. package/dist/db/adapter/index.cjs +0 -0
  8. package/dist/db/adapter/index.d.cts +7 -0
  9. package/dist/db/adapter/index.d.ts +7 -0
  10. package/dist/db/adapter/index.js +1 -0
  11. package/dist/db/index.cjs +67 -1
  12. package/dist/db/index.d.cts +3 -130
  13. package/dist/db/index.d.ts +3 -130
  14. package/dist/db/index.js +61 -0
  15. package/dist/env/index.cjs +16 -0
  16. package/dist/env/index.d.cts +2 -0
  17. package/dist/env/index.d.ts +2 -0
  18. package/dist/env/index.js +3 -0
  19. package/dist/env-B05JceKx.cjs +330 -0
  20. package/dist/env-BZ5Nwx0e.js +246 -0
  21. package/dist/error/index.cjs +5 -0
  22. package/dist/error/index.d.cts +35 -0
  23. package/dist/error/index.d.ts +35 -0
  24. package/dist/error/index.js +4 -0
  25. package/dist/error-Hbg10Ynz.cjs +56 -0
  26. package/dist/error-ULaqTKlI.js +45 -0
  27. package/dist/helper-5oNxdxzu.d.ts +6 -0
  28. package/dist/helper-DVgWo5zB.d.cts +6 -0
  29. package/dist/index-B7m2jDWm.d.cts +344 -0
  30. package/dist/index-CESTxPyW.d.cts +82 -0
  31. package/dist/index-Cw9Gfaxd.d.cts +4410 -0
  32. package/dist/index-Cx8dCSTo.d.ts +82 -0
  33. package/dist/index-DJdmnKQr.d.ts +4410 -0
  34. package/dist/index-DNvIh1jX.d.cts +1870 -0
  35. package/dist/index-DoyF8K2U.d.ts +344 -0
  36. package/dist/index-ujq2DkG7.d.ts +1870 -0
  37. package/dist/index.cjs +0 -2
  38. package/dist/index.d.cts +7 -2
  39. package/dist/index.d.ts +7 -2
  40. package/dist/index.js +1 -0
  41. package/dist/middleware/index.cjs +22 -0
  42. package/dist/middleware/index.d.cts +7 -0
  43. package/dist/middleware/index.d.ts +7 -0
  44. package/dist/middleware/index.js +18 -0
  45. package/dist/oauth2/index.cjs +12 -0
  46. package/dist/oauth2/index.d.cts +3 -0
  47. package/dist/oauth2/index.d.ts +3 -0
  48. package/dist/oauth2/index.js +3 -0
  49. package/dist/oauth2-BokgssHJ.js +239 -0
  50. package/dist/oauth2-CLON8fY4.cjs +302 -0
  51. package/dist/social-providers/index.cjs +2410 -0
  52. package/dist/social-providers/index.d.cts +4 -0
  53. package/dist/social-providers/index.d.ts +4 -0
  54. package/dist/social-providers/index.js +2370 -0
  55. package/dist/type-BNCR-kIK.d.cts +262 -0
  56. package/dist/type-eT5TjHFp.d.ts +262 -0
  57. package/dist/utils/index.cjs +3 -0
  58. package/dist/utils/index.d.cts +9 -0
  59. package/dist/utils/index.d.ts +9 -0
  60. package/dist/utils/index.js +3 -0
  61. package/dist/utils-AcCtPmwG.cjs +13 -0
  62. package/dist/utils-BQjFFU97.js +7 -0
  63. package/package.json +116 -10
  64. package/src/async_hooks/index.ts +1 -9
  65. package/src/db/adapter/index.ts +448 -0
  66. package/src/db/index.ts +15 -0
  67. package/src/db/plugin.ts +11 -0
  68. package/src/db/schema/account.ts +34 -0
  69. package/src/db/schema/rate-limit.ts +21 -0
  70. package/src/db/schema/session.ts +17 -0
  71. package/src/db/schema/shared.ts +7 -0
  72. package/src/db/schema/user.ts +16 -0
  73. package/src/db/schema/verification.ts +15 -0
  74. package/src/db/type.ts +41 -0
  75. package/src/env/color-depth.ts +171 -0
  76. package/src/env/env-impl.ts +123 -0
  77. package/src/env/index.ts +23 -0
  78. package/src/env/logger.test.ts +33 -0
  79. package/src/env/logger.ts +145 -0
  80. package/src/error/codes.ts +31 -0
  81. package/src/error/index.ts +11 -0
  82. package/src/index.ts +1 -1
  83. package/src/middleware/index.ts +33 -0
  84. package/src/oauth2/client-credentials-token.ts +102 -0
  85. package/src/oauth2/create-authorization-url.ts +85 -0
  86. package/src/oauth2/index.ts +22 -0
  87. package/src/oauth2/oauth-provider.ts +194 -0
  88. package/src/oauth2/refresh-access-token.ts +124 -0
  89. package/src/oauth2/utils.ts +36 -0
  90. package/src/oauth2/validate-authorization-code.ts +156 -0
  91. package/src/social-providers/apple.ts +213 -0
  92. package/src/social-providers/atlassian.ts +127 -0
  93. package/src/social-providers/cognito.ts +266 -0
  94. package/src/social-providers/discord.ts +169 -0
  95. package/src/social-providers/dropbox.ts +112 -0
  96. package/src/social-providers/facebook.ts +201 -0
  97. package/src/social-providers/figma.ts +112 -0
  98. package/src/social-providers/github.ts +154 -0
  99. package/src/social-providers/gitlab.ts +152 -0
  100. package/src/social-providers/google.ts +168 -0
  101. package/src/social-providers/huggingface.ts +116 -0
  102. package/src/social-providers/index.ts +118 -0
  103. package/src/social-providers/kakao.ts +178 -0
  104. package/src/social-providers/kick.ts +92 -0
  105. package/src/social-providers/line.ts +169 -0
  106. package/src/social-providers/linear.ts +120 -0
  107. package/src/social-providers/linkedin.ts +110 -0
  108. package/src/social-providers/microsoft-entra-id.ts +243 -0
  109. package/src/social-providers/naver.ts +112 -0
  110. package/src/social-providers/notion.ts +106 -0
  111. package/src/social-providers/paypal.ts +261 -0
  112. package/src/social-providers/reddit.ts +122 -0
  113. package/src/social-providers/roblox.ts +107 -0
  114. package/src/social-providers/salesforce.ts +154 -0
  115. package/src/social-providers/slack.ts +111 -0
  116. package/src/social-providers/spotify.ts +93 -0
  117. package/src/social-providers/tiktok.ts +208 -0
  118. package/src/social-providers/twitch.ts +111 -0
  119. package/src/social-providers/twitter.ts +194 -0
  120. package/src/social-providers/vk.ts +125 -0
  121. package/src/social-providers/zoom.ts +215 -0
  122. package/src/types/context.ts +270 -0
  123. package/src/types/cookie.ts +7 -0
  124. package/src/types/helper.ts +5 -0
  125. package/src/types/index.ts +20 -1
  126. package/src/types/init-options.ts +1156 -0
  127. package/src/types/plugin-client.ts +69 -0
  128. package/src/types/plugin.ts +134 -0
  129. package/src/utils/error-codes.ts +51 -0
  130. package/src/utils/index.ts +1 -0
  131. package/tsdown.config.ts +19 -0
  132. package/build.config.ts +0 -16
  133. package/dist/async_hooks/index.d.mts +0 -10
  134. package/dist/async_hooks/index.mjs +0 -25
  135. package/dist/db/index.d.mts +0 -130
  136. package/dist/db/index.mjs +0 -1
  137. package/dist/index.d.mts +0 -2
  138. package/dist/index.mjs +0 -1
@@ -0,0 +1,69 @@
1
+ import type { BetterAuthPlugin } from "./plugin";
2
+ import type {
3
+ BetterFetch,
4
+ BetterFetchOption,
5
+ BetterFetchPlugin,
6
+ } from "@better-fetch/fetch";
7
+ import type { LiteralString } from "./helper";
8
+ import type { BetterAuthOptions } from "./init-options";
9
+ import type { WritableAtom, Atom } from "nanostores";
10
+
11
+ export interface ClientStore {
12
+ notify: (signal: string) => void;
13
+ listen: (signal: string, listener: () => void) => void;
14
+ atoms: Record<string, WritableAtom<any>>;
15
+ }
16
+
17
+ export type ClientAtomListener = {
18
+ matcher: (path: string) => boolean;
19
+ signal: "$sessionSignal" | Omit<string, "$sessionSignal">;
20
+ };
21
+
22
+ export interface BetterAuthClientOptions {
23
+ fetchOptions?: BetterFetchOption;
24
+ plugins?: BetterAuthClientPlugin[];
25
+ baseURL?: string;
26
+ basePath?: string;
27
+ disableDefaultFetchPlugins?: boolean;
28
+ $InferAuth?: BetterAuthOptions;
29
+ }
30
+
31
+ export interface BetterAuthClientPlugin {
32
+ id: LiteralString;
33
+ /**
34
+ * only used for type inference. don't pass the
35
+ * actual plugin
36
+ */
37
+ $InferServerPlugin?: BetterAuthPlugin;
38
+ /**
39
+ * Custom actions
40
+ */
41
+ getActions?: (
42
+ $fetch: BetterFetch,
43
+ $store: ClientStore,
44
+ /**
45
+ * better-auth client options
46
+ */
47
+ options: BetterAuthClientOptions | undefined,
48
+ ) => Record<string, any>;
49
+ /**
50
+ * State atoms that'll be resolved by each framework
51
+ * auth store.
52
+ */
53
+ getAtoms?: ($fetch: BetterFetch) => Record<string, Atom<any>>;
54
+ /**
55
+ * specify path methods for server plugin inferred
56
+ * endpoints to force a specific method.
57
+ */
58
+ pathMethods?: Record<string, "POST" | "GET">;
59
+ /**
60
+ * Better fetch plugins
61
+ */
62
+ fetchPlugins?: BetterFetchPlugin[];
63
+ /**
64
+ * a list of recaller based on a matcher function.
65
+ * The signal name needs to match a signal in this
66
+ * plugin or any plugin the user might have added.
67
+ */
68
+ atomListeners?: ClientAtomListener[];
69
+ }
@@ -0,0 +1,134 @@
1
+ import type { Migration } from "kysely";
2
+ import type { AuthContext } from "./context";
3
+ import type {
4
+ Endpoint,
5
+ EndpointContext,
6
+ InputContext,
7
+ Middleware,
8
+ } from "better-call";
9
+ import type { BetterAuthPluginDBSchema } from "../db";
10
+ import type { LiteralString } from "./helper";
11
+ import type { BetterAuthOptions } from "./init-options";
12
+ import type { AuthMiddleware } from "../middleware";
13
+
14
+ type Awaitable<T> = T | Promise<T>;
15
+ type DeepPartial<T> = T extends Function
16
+ ? T
17
+ : T extends object
18
+ ? { [K in keyof T]?: DeepPartial<T[K]> }
19
+ : T;
20
+
21
+ type HookEndpointContext = EndpointContext<string, any> &
22
+ Omit<InputContext<string, any>, "method"> & {
23
+ context: AuthContext & {
24
+ returned?: unknown;
25
+ responseHeaders?: Headers;
26
+ };
27
+ headers?: Headers;
28
+ };
29
+
30
+ export type BetterAuthPlugin = {
31
+ id: LiteralString;
32
+ /**
33
+ * The init function is called when the plugin is initialized.
34
+ * You can return a new context or modify the existing context.
35
+ */
36
+ init?: (ctx: AuthContext) =>
37
+ | Awaitable<{
38
+ context?: DeepPartial<Omit<AuthContext, "options">>;
39
+ options?: Partial<BetterAuthOptions>;
40
+ }>
41
+ | void
42
+ | Promise<void>;
43
+ endpoints?: {
44
+ [key: string]: Endpoint;
45
+ };
46
+ middlewares?: {
47
+ path: string;
48
+ middleware: Middleware;
49
+ }[];
50
+ onRequest?: (
51
+ request: Request,
52
+ ctx: AuthContext,
53
+ ) => Promise<
54
+ | {
55
+ response: Response;
56
+ }
57
+ | {
58
+ request: Request;
59
+ }
60
+ | void
61
+ >;
62
+ onResponse?: (
63
+ response: Response,
64
+ ctx: AuthContext,
65
+ ) => Promise<{
66
+ response: Response;
67
+ } | void>;
68
+ hooks?: {
69
+ before?: {
70
+ matcher: (context: HookEndpointContext) => boolean;
71
+ handler: AuthMiddleware;
72
+ }[];
73
+ after?: {
74
+ matcher: (context: HookEndpointContext) => boolean;
75
+ handler: AuthMiddleware;
76
+ }[];
77
+ };
78
+ /**
79
+ * Schema the plugin needs
80
+ *
81
+ * This will also be used to migrate the database. If the fields are dynamic from the plugins
82
+ * configuration each time the configuration is changed a new migration will be created.
83
+ *
84
+ * NOTE: If you want to create migrations manually using
85
+ * migrations option or any other way you
86
+ * can disable migration per table basis.
87
+ *
88
+ * @example
89
+ * ```ts
90
+ * schema: {
91
+ * user: {
92
+ * fields: {
93
+ * email: {
94
+ * type: "string",
95
+ * },
96
+ * emailVerified: {
97
+ * type: "boolean",
98
+ * defaultValue: false,
99
+ * },
100
+ * },
101
+ * }
102
+ * } as AuthPluginSchema
103
+ * ```
104
+ */
105
+ schema?: BetterAuthPluginDBSchema;
106
+ /**
107
+ * The migrations of the plugin. If you define schema that will automatically create
108
+ * migrations for you.
109
+ *
110
+ * ⚠️ Only uses this if you dont't want to use the schema option and you disabled migrations for
111
+ * the tables.
112
+ */
113
+ migrations?: Record<string, Migration>;
114
+ /**
115
+ * The options of the plugin
116
+ */
117
+ options?: Record<string, any> | undefined;
118
+ /**
119
+ * types to be inferred
120
+ */
121
+ $Infer?: Record<string, any>;
122
+ /**
123
+ * The rate limit rules to apply to specific paths.
124
+ */
125
+ rateLimit?: {
126
+ window: number;
127
+ max: number;
128
+ pathMatcher: (path: string) => boolean;
129
+ }[];
130
+ /**
131
+ * The error codes returned by the plugin
132
+ */
133
+ $ERROR_CODES?: Record<string, string>;
134
+ };
@@ -0,0 +1,51 @@
1
+ type UpperLetter =
2
+ | "A"
3
+ | "B"
4
+ | "C"
5
+ | "D"
6
+ | "E"
7
+ | "F"
8
+ | "G"
9
+ | "H"
10
+ | "I"
11
+ | "J"
12
+ | "K"
13
+ | "L"
14
+ | "M"
15
+ | "N"
16
+ | "O"
17
+ | "P"
18
+ | "Q"
19
+ | "R"
20
+ | "S"
21
+ | "T"
22
+ | "U"
23
+ | "V"
24
+ | "W"
25
+ | "X"
26
+ | "Y"
27
+ | "Z";
28
+ type SpecialCharacter = "_";
29
+
30
+ type IsValidUpperSnakeCase<S extends string> = S extends `${infer F}${infer R}`
31
+ ? F extends UpperLetter | SpecialCharacter
32
+ ? IsValidUpperSnakeCase<R>
33
+ : false
34
+ : true;
35
+
36
+ type InvalidKeyError<K extends string> =
37
+ `Invalid error code key: "${K}" - must only contain uppercase letters (A-Z) and underscores (_)`;
38
+
39
+ type ValidateErrorCodes<T> = {
40
+ [K in keyof T]: K extends string
41
+ ? IsValidUpperSnakeCase<K> extends false
42
+ ? InvalidKeyError<K>
43
+ : T[K]
44
+ : T[K];
45
+ };
46
+
47
+ export function defineErrorCodes<const T extends Record<string, string>>(
48
+ codes: ValidateErrorCodes<T>,
49
+ ): T {
50
+ return codes as T;
51
+ }
@@ -0,0 +1 @@
1
+ export { defineErrorCodes } from "./error-codes";
@@ -0,0 +1,19 @@
1
+ import { defineConfig } from "tsdown";
2
+
3
+ export default defineConfig({
4
+ dts: true,
5
+ format: ["esm", "cjs"],
6
+ entry: [
7
+ "./src/index.ts",
8
+ "./src/db/index.ts",
9
+ "./src/db/adapter/index.ts",
10
+ "./src/async_hooks/index.ts",
11
+ "./src/env/index.ts",
12
+ "./src/oauth2/index.ts",
13
+ "./src/middleware/index.ts",
14
+ "./src/social-providers/index.ts",
15
+ "./src/utils/index.ts",
16
+ "./src/error/index.ts",
17
+ ],
18
+ clean: true,
19
+ });
package/build.config.ts DELETED
@@ -1,16 +0,0 @@
1
- import { defineBuildConfig } from "unbuild";
2
-
3
- export default defineBuildConfig({
4
- rollup: {
5
- emitCJS: true,
6
- },
7
- declaration: true,
8
- outDir: "dist",
9
- clean: true,
10
- failOnWarn: false,
11
- entries: [
12
- "./src/index.ts",
13
- "./src/db/index.ts",
14
- "./src/async_hooks/index.ts",
15
- ],
16
- });
@@ -1,10 +0,0 @@
1
- import { AsyncLocalStorage } from 'node:async_hooks';
2
- export { AsyncLocalStorage } from 'node:async_hooks';
3
-
4
- /**
5
- * AsyncLocalStorage will be import directly in 1.5.x
6
- */
7
-
8
- declare function getAsyncLocalStorage(): Promise<typeof AsyncLocalStorage>;
9
-
10
- export { getAsyncLocalStorage };
@@ -1,25 +0,0 @@
1
- let moduleName = "node:async_hooks";
2
- const AsyncLocalStoragePromise = import(
3
- /* @vite-ignore */
4
- /* webpackIgnore: true */
5
- moduleName
6
- ).then((mod) => mod.AsyncLocalStorage).catch((err) => {
7
- if ("AsyncLocalStorage" in globalThis) {
8
- return globalThis.AsyncLocalStorage;
9
- }
10
- console.warn(
11
- "[better-auth] Warning: AsyncLocalStorage is not available in this environment. Some features may not work as expected."
12
- );
13
- console.warn(
14
- "[better-auth] Please read more about this warning at https://better-auth.com/docs/installation#mount-handler"
15
- );
16
- console.warn(
17
- "[better-auth] If you are using Cloudflare Workers, please see: https://developers.cloudflare.com/workers/configuration/compatibility-flags/#nodejs-compatibility-flag"
18
- );
19
- throw err;
20
- });
21
- async function getAsyncLocalStorage() {
22
- return AsyncLocalStoragePromise;
23
- }
24
-
25
- export { getAsyncLocalStorage };
@@ -1,130 +0,0 @@
1
- import { ZodType } from 'zod';
2
-
3
- type LiteralString = "" | (string & Record<never, never>);
4
-
5
- type DBFieldType = "string" | "number" | "boolean" | "date" | "json" | `${"string" | "number"}[]` | Array<LiteralString>;
6
- type DBPrimitive = string | number | boolean | Date | null | undefined | string[] | number[];
7
- type DBFieldAttributeConfig = {
8
- /**
9
- * If the field should be required on a new record.
10
- * @default true
11
- */
12
- required?: boolean;
13
- /**
14
- * If the value should be returned on a response body.
15
- * @default true
16
- */
17
- returned?: boolean;
18
- /**
19
- * If a value should be provided when creating a new record.
20
- * @default true
21
- */
22
- input?: boolean;
23
- /**
24
- * Default value for the field
25
- *
26
- * Note: This will not create a default value on the database level. It will only
27
- * be used when creating a new record.
28
- */
29
- defaultValue?: DBPrimitive | (() => DBPrimitive);
30
- /**
31
- * Update value for the field
32
- *
33
- * Note: This will create an onUpdate trigger on the database level for supported adapters.
34
- * It will be called when updating a record.
35
- */
36
- onUpdate?: () => DBPrimitive;
37
- /**
38
- * transform the value before storing it.
39
- */
40
- transform?: {
41
- input?: (value: DBPrimitive) => DBPrimitive | Promise<DBPrimitive>;
42
- output?: (value: DBPrimitive) => DBPrimitive | Promise<DBPrimitive>;
43
- };
44
- /**
45
- * Reference to another model.
46
- */
47
- references?: {
48
- /**
49
- * The model to reference.
50
- */
51
- model: string;
52
- /**
53
- * The field on the referenced model.
54
- */
55
- field: string;
56
- /**
57
- * The action to perform when the reference is deleted.
58
- * @default "cascade"
59
- */
60
- onDelete?: "no action" | "restrict" | "cascade" | "set null" | "set default";
61
- };
62
- unique?: boolean;
63
- /**
64
- * If the field should be a bigint on the database instead of integer.
65
- */
66
- bigint?: boolean;
67
- /**
68
- * A zod schema to validate the value.
69
- */
70
- validator?: {
71
- input?: ZodType;
72
- output?: ZodType;
73
- };
74
- /**
75
- * The name of the field on the database.
76
- */
77
- fieldName?: string;
78
- /**
79
- * If the field should be sortable.
80
- *
81
- * applicable only for `text` type.
82
- * It's useful to mark fields varchar instead of text.
83
- */
84
- sortable?: boolean;
85
- };
86
- type DBFieldAttribute<T extends DBFieldType = DBFieldType> = {
87
- type: T;
88
- } & DBFieldAttributeConfig;
89
- type BetterAuthDBSchema = Record<string, {
90
- /**
91
- * The name of the table in the database
92
- */
93
- modelName: string;
94
- /**
95
- * The fields of the table
96
- */
97
- fields: Record<string, DBFieldAttribute>;
98
- /**
99
- * Whether to disable migrations for this table
100
- * @default false
101
- */
102
- disableMigrations?: boolean;
103
- /**
104
- * The order of the table
105
- */
106
- order?: number;
107
- }>;
108
-
109
- /**
110
- * @deprecated Backport for 1.3.x, we will remove this in 1.4.x
111
- */
112
- type FieldAttribute = DBFieldAttribute;
113
- /**
114
- * @deprecated Backport for 1.3.x, we will remove this in 1.4.x
115
- */
116
- type FieldAttributeConfig = DBFieldAttributeConfig;
117
- /**
118
- * @deprecated Backport for 1.3.x, we will remove this in 1.4.x
119
- */
120
- type FieldType = DBFieldType;
121
- /**
122
- * @deprecated Backport for 1.3.x, we will remove this in 1.4.x
123
- */
124
- type Primitive = DBPrimitive;
125
- /**
126
- * @deprecated Backport for 1.3.x, we will remove this in 1.4.x
127
- */
128
- type BetterAuthDbSchema = BetterAuthDBSchema;
129
-
130
- export type { BetterAuthDBSchema, BetterAuthDbSchema, DBFieldAttribute, DBFieldAttributeConfig, DBFieldType, DBPrimitive, FieldAttribute, FieldAttributeConfig, FieldType, Primitive };
package/dist/db/index.mjs DELETED
@@ -1 +0,0 @@
1
-
package/dist/index.d.mts DELETED
@@ -1,2 +0,0 @@
1
-
2
- export { };
package/dist/index.mjs DELETED
@@ -1 +0,0 @@
1
-