@better-auth/core 1.4.0-beta.7 → 1.4.0-beta.9

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 (124) hide show
  1. package/.turbo/turbo-build.log +54 -4
  2. package/build.config.ts +6 -0
  3. package/dist/db/adapter/index.d.cts +14 -23
  4. package/dist/db/adapter/index.d.mts +14 -23
  5. package/dist/db/adapter/index.d.ts +14 -23
  6. package/dist/db/index.cjs +16 -0
  7. package/dist/db/index.d.cts +6 -83
  8. package/dist/db/index.d.mts +6 -83
  9. package/dist/db/index.d.ts +6 -83
  10. package/dist/db/index.mjs +16 -1
  11. package/dist/env/index.cjs +315 -0
  12. package/dist/env/index.d.cts +36 -0
  13. package/dist/env/index.d.mts +36 -0
  14. package/dist/env/index.d.ts +36 -0
  15. package/dist/env/index.mjs +300 -0
  16. package/dist/error/index.cjs +44 -0
  17. package/dist/error/index.d.cts +33 -0
  18. package/dist/error/index.d.mts +33 -0
  19. package/dist/error/index.d.ts +33 -0
  20. package/dist/error/index.mjs +41 -0
  21. package/dist/index.d.cts +159 -94
  22. package/dist/index.d.mts +159 -94
  23. package/dist/index.d.ts +159 -94
  24. package/dist/middleware/index.cjs +25 -0
  25. package/dist/middleware/index.d.cts +14 -0
  26. package/dist/middleware/index.d.mts +14 -0
  27. package/dist/middleware/index.d.ts +14 -0
  28. package/dist/middleware/index.mjs +21 -0
  29. package/dist/oauth2/index.cjs +368 -0
  30. package/dist/oauth2/index.d.cts +99 -0
  31. package/dist/oauth2/index.d.mts +99 -0
  32. package/dist/oauth2/index.d.ts +99 -0
  33. package/dist/oauth2/index.mjs +357 -0
  34. package/dist/shared/core.2rWMW9q9.d.ts +13 -0
  35. package/dist/shared/core.40VTWh-p.d.cts +217 -0
  36. package/dist/shared/core.BfcVdsSf.d.cts +181 -0
  37. package/dist/shared/core.Bisb2Bdk.d.mts +181 -0
  38. package/dist/shared/core.BwoNUcJQ.d.cts +53 -0
  39. package/dist/shared/core.BwoNUcJQ.d.mts +53 -0
  40. package/dist/shared/core.BwoNUcJQ.d.ts +53 -0
  41. package/dist/shared/core.CErFRCOZ.d.mts +1684 -0
  42. package/dist/shared/core.CGN6D-Mh.d.ts +181 -0
  43. package/dist/shared/core.CPuIItYE.d.ts +217 -0
  44. package/dist/shared/core.CftpHMDz.d.cts +13 -0
  45. package/dist/shared/core.Db7zJyxf.d.ts +1684 -0
  46. package/dist/shared/core.DqaxObkf.d.cts +1684 -0
  47. package/dist/shared/core.MjcDoj7R.d.cts +5 -0
  48. package/dist/shared/core.MjcDoj7R.d.mts +5 -0
  49. package/dist/shared/core.MjcDoj7R.d.ts +5 -0
  50. package/dist/shared/core.g2ZbxAEV.d.mts +217 -0
  51. package/dist/shared/core.g9ACQ8v2.d.mts +13 -0
  52. package/dist/social-providers/index.cjs +2793 -0
  53. package/dist/social-providers/index.d.cts +3903 -0
  54. package/dist/social-providers/index.d.mts +3903 -0
  55. package/dist/social-providers/index.d.ts +3903 -0
  56. package/dist/social-providers/index.mjs +2743 -0
  57. package/dist/utils/index.cjs +7 -0
  58. package/dist/utils/index.d.cts +10 -0
  59. package/dist/utils/index.d.mts +10 -0
  60. package/dist/utils/index.d.ts +10 -0
  61. package/dist/utils/index.mjs +5 -0
  62. package/package.json +99 -2
  63. package/src/db/adapter/index.ts +424 -0
  64. package/src/db/index.ts +4 -0
  65. package/src/db/schema/rate-limit.ts +21 -0
  66. package/src/db/type.ts +29 -10
  67. package/src/env/color-depth.ts +171 -0
  68. package/src/env/env-impl.ts +123 -0
  69. package/src/env/index.ts +23 -0
  70. package/src/env/logger.test.ts +33 -0
  71. package/src/env/logger.ts +145 -0
  72. package/src/error/codes.ts +31 -0
  73. package/src/error/index.ts +11 -0
  74. package/src/index.ts +0 -2
  75. package/src/middleware/index.ts +33 -0
  76. package/src/oauth2/client-credentials-token.ts +102 -0
  77. package/src/oauth2/create-authorization-url.ts +85 -0
  78. package/src/oauth2/index.ts +22 -0
  79. package/src/oauth2/oauth-provider.ts +194 -0
  80. package/src/oauth2/refresh-access-token.ts +124 -0
  81. package/src/oauth2/utils.ts +36 -0
  82. package/src/oauth2/validate-authorization-code.ts +156 -0
  83. package/src/social-providers/apple.ts +213 -0
  84. package/src/social-providers/atlassian.ts +130 -0
  85. package/src/social-providers/cognito.ts +269 -0
  86. package/src/social-providers/discord.ts +172 -0
  87. package/src/social-providers/dropbox.ts +112 -0
  88. package/src/social-providers/facebook.ts +204 -0
  89. package/src/social-providers/figma.ts +115 -0
  90. package/src/social-providers/github.ts +154 -0
  91. package/src/social-providers/gitlab.ts +152 -0
  92. package/src/social-providers/google.ts +171 -0
  93. package/src/social-providers/huggingface.ts +116 -0
  94. package/src/social-providers/index.ts +118 -0
  95. package/src/social-providers/kakao.ts +178 -0
  96. package/src/social-providers/kick.ts +95 -0
  97. package/src/social-providers/line.ts +169 -0
  98. package/src/social-providers/linear.ts +120 -0
  99. package/src/social-providers/linkedin.ts +110 -0
  100. package/src/social-providers/microsoft-entra-id.ts +243 -0
  101. package/src/social-providers/naver.ts +112 -0
  102. package/src/social-providers/notion.ts +106 -0
  103. package/src/social-providers/paypal.ts +261 -0
  104. package/src/social-providers/reddit.ts +122 -0
  105. package/src/social-providers/roblox.ts +110 -0
  106. package/src/social-providers/salesforce.ts +157 -0
  107. package/src/social-providers/slack.ts +114 -0
  108. package/src/social-providers/spotify.ts +93 -0
  109. package/src/social-providers/tiktok.ts +211 -0
  110. package/src/social-providers/twitch.ts +111 -0
  111. package/src/social-providers/twitter.ts +194 -0
  112. package/src/social-providers/vk.ts +128 -0
  113. package/src/social-providers/zoom.ts +218 -0
  114. package/src/types/context.ts +270 -0
  115. package/src/types/cookie.ts +7 -0
  116. package/src/types/index.ts +19 -1
  117. package/src/types/init-options.ts +1039 -2
  118. package/src/types/plugin-client.ts +69 -0
  119. package/src/types/plugin.ts +134 -0
  120. package/src/utils/error-codes.ts +51 -0
  121. package/src/utils/index.ts +1 -0
  122. package/dist/shared/core.CnvFgghY.d.cts +0 -117
  123. package/dist/shared/core.CnvFgghY.d.mts +0 -117
  124. package/dist/shared/core.CnvFgghY.d.ts +0 -117
package/dist/index.d.cts CHANGED
@@ -1,115 +1,180 @@
1
- import { L as LiteralUnion, M as Models } from './shared/core.CnvFgghY.cjs';
2
- export { a as LiteralString } from './shared/core.CnvFgghY.cjs';
3
- import { CookieOptions } from 'better-call';
1
+ import { L as LiteralString } from './shared/core.MjcDoj7R.cjs';
2
+ export { a as LiteralUnion } from './shared/core.MjcDoj7R.cjs';
3
+ import { A as AuthContext, B as BetterAuthOptions, a as AuthMiddleware } from './shared/core.DqaxObkf.cjs';
4
+ export { b as BetterAuthAdvancedOptions, d as BetterAuthCookies, c as BetterAuthRateLimitOptions, G as GenerateIdFn, e as GenericEndpointContext, I as InternalAdapter } from './shared/core.DqaxObkf.cjs';
5
+ import { Migration } from 'kysely';
6
+ import { Endpoint, Middleware, EndpointContext, InputContext } from 'better-call';
7
+ import { B as BetterAuthPluginDBSchema } from './shared/core.CftpHMDz.cjs';
8
+ import { BetterFetch, BetterFetchOption, BetterFetchPlugin } from '@better-fetch/fetch';
9
+ import { WritableAtom, Atom } from 'nanostores';
10
+ import 'better-sqlite3';
11
+ import './shared/core.40VTWh-p.cjs';
4
12
  import 'zod';
13
+ import 'bun:sqlite';
14
+ import 'node:sqlite';
15
+ import './social-providers/index.cjs';
16
+ import '@better-auth/core/oauth2';
17
+ import './shared/core.BfcVdsSf.cjs';
18
+ import './shared/core.BwoNUcJQ.cjs';
19
+ import '@better-auth/core';
5
20
 
6
- type GenerateIdFn = (options: {
7
- model: LiteralUnion<Models, string>;
8
- size?: number;
9
- }) => string | false;
10
- type BetterAuthAdvancedOptions = {
21
+ type Awaitable<T> = T | Promise<T>;
22
+ type DeepPartial<T> = T extends Function ? T : T extends object ? {
23
+ [K in keyof T]?: DeepPartial<T[K]>;
24
+ } : T;
25
+ type HookEndpointContext = EndpointContext<string, any> & Omit<InputContext<string, any>, "method"> & {
26
+ context: AuthContext & {
27
+ returned?: unknown;
28
+ responseHeaders?: Headers;
29
+ };
30
+ headers?: Headers;
31
+ };
32
+ type BetterAuthPlugin = {
33
+ id: LiteralString;
11
34
  /**
12
- * Ip address configuration
35
+ * The init function is called when the plugin is initialized.
36
+ * You can return a new context or modify the existing context.
13
37
  */
14
- ipAddress?: {
15
- /**
16
- * List of headers to use for ip address
17
- *
18
- * Ip address is used for rate limiting and session tracking
19
- *
20
- * @example ["x-client-ip", "x-forwarded-for", "cf-connecting-ip"]
21
- *
22
- * @default
23
- * @link https://github.com/better-auth/better-auth/blob/main/packages/better-auth/src/utils/get-request-ip.ts#L8
24
- */
25
- ipAddressHeaders?: string[];
26
- /**
27
- * Disable ip tracking
28
- *
29
- * ⚠︎ This is a security risk and it may expose your application to abuse
30
- */
31
- disableIpTracking?: boolean;
38
+ init?: (ctx: AuthContext) => Awaitable<{
39
+ context?: DeepPartial<Omit<AuthContext, "options">>;
40
+ options?: Partial<BetterAuthOptions>;
41
+ }> | void | Promise<void>;
42
+ endpoints?: {
43
+ [key: string]: Endpoint;
44
+ };
45
+ middlewares?: {
46
+ path: string;
47
+ middleware: Middleware;
48
+ }[];
49
+ onRequest?: (request: Request, ctx: AuthContext) => Promise<{
50
+ response: Response;
51
+ } | {
52
+ request: Request;
53
+ } | void>;
54
+ onResponse?: (response: Response, ctx: AuthContext) => Promise<{
55
+ response: Response;
56
+ } | void>;
57
+ hooks?: {
58
+ before?: {
59
+ matcher: (context: HookEndpointContext) => boolean;
60
+ handler: AuthMiddleware;
61
+ }[];
62
+ after?: {
63
+ matcher: (context: HookEndpointContext) => boolean;
64
+ handler: AuthMiddleware;
65
+ }[];
32
66
  };
33
67
  /**
34
- * Use secure cookies
68
+ * Schema the plugin needs
69
+ *
70
+ * This will also be used to migrate the database. If the fields are dynamic from the plugins
71
+ * configuration each time the configuration is changed a new migration will be created.
35
72
  *
36
- * @default false
73
+ * NOTE: If you want to create migrations manually using
74
+ * migrations option or any other way you
75
+ * can disable migration per table basis.
76
+ *
77
+ * @example
78
+ * ```ts
79
+ * schema: {
80
+ * user: {
81
+ * fields: {
82
+ * email: {
83
+ * type: "string",
84
+ * },
85
+ * emailVerified: {
86
+ * type: "boolean",
87
+ * defaultValue: false,
88
+ * },
89
+ * },
90
+ * }
91
+ * } as AuthPluginSchema
92
+ * ```
37
93
  */
38
- useSecureCookies?: boolean;
94
+ schema?: BetterAuthPluginDBSchema;
39
95
  /**
40
- * Disable trusted origins check
96
+ * The migrations of the plugin. If you define schema that will automatically create
97
+ * migrations for you.
41
98
  *
42
- * ⚠︎ This is a security risk and it may expose your application to CSRF attacks
99
+ * ⚠️ Only uses this if you dont't want to use the schema option and you disabled migrations for
100
+ * the tables.
43
101
  */
44
- disableCSRFCheck?: boolean;
102
+ migrations?: Record<string, Migration>;
45
103
  /**
46
- * Configure cookies to be cross subdomains
104
+ * The options of the plugin
47
105
  */
48
- crossSubDomainCookies?: {
49
- /**
50
- * Enable cross subdomain cookies
51
- */
52
- enabled: boolean;
53
- /**
54
- * Additional cookies to be shared across subdomains
55
- */
56
- additionalCookies?: string[];
57
- /**
58
- * The domain to use for the cookies
59
- *
60
- * By default, the domain will be the root
61
- * domain from the base URL.
62
- */
63
- domain?: string;
64
- };
65
- cookies?: {
66
- [key: string]: {
67
- name?: string;
68
- attributes?: CookieOptions;
69
- };
70
- };
71
- defaultCookieAttributes?: CookieOptions;
106
+ options?: Record<string, any> | undefined;
72
107
  /**
73
- * Prefix for cookies. If a cookie name is provided
74
- * in cookies config, this will be overridden.
75
- *
76
- * @default
77
- * ```txt
78
- * "appName" -> which defaults to "better-auth"
79
- * ```
108
+ * types to be inferred
80
109
  */
81
- cookiePrefix?: string;
110
+ $Infer?: Record<string, any>;
82
111
  /**
83
- * Database configuration.
112
+ * The rate limit rules to apply to specific paths.
84
113
  */
85
- database?: {
86
- /**
87
- * The default number of records to return from the database
88
- * when using the `findMany` adapter method.
89
- *
90
- * @default 100
91
- */
92
- defaultFindManyLimit?: number;
93
- /**
94
- * If your database auto increments number ids, set this to `true`.
95
- *
96
- * Note: If enabled, we will not handle ID generation (including if you use `generateId`), and it would be expected that your database will provide the ID automatically.
97
- *
98
- * @default false
99
- */
100
- useNumberId?: boolean;
101
- /**
102
- * Custom generateId function.
103
- *
104
- * If not provided, random ids will be generated.
105
- * If set to false, the database's auto generated id will be used.
106
- */
107
- generateId?: GenerateIdFn | false;
108
- };
114
+ rateLimit?: {
115
+ window: number;
116
+ max: number;
117
+ pathMatcher: (path: string) => boolean;
118
+ }[];
119
+ /**
120
+ * The error codes returned by the plugin
121
+ */
122
+ $ERROR_CODES?: Record<string, string>;
109
123
  };
110
124
 
111
- interface BetterAuthMutators<O, C> {
125
+ interface ClientStore {
126
+ notify: (signal: string) => void;
127
+ listen: (signal: string, listener: () => void) => void;
128
+ atoms: Record<string, WritableAtom<any>>;
129
+ }
130
+ type ClientAtomListener = {
131
+ matcher: (path: string) => boolean;
132
+ signal: "$sessionSignal" | Omit<string, "$sessionSignal">;
133
+ };
134
+ interface BetterAuthClientOptions {
135
+ fetchOptions?: BetterFetchOption;
136
+ plugins?: BetterAuthClientPlugin[];
137
+ baseURL?: string;
138
+ basePath?: string;
139
+ disableDefaultFetchPlugins?: boolean;
140
+ $InferAuth?: BetterAuthOptions;
141
+ }
142
+ interface BetterAuthClientPlugin {
143
+ id: LiteralString;
144
+ /**
145
+ * only used for type inference. don't pass the
146
+ * actual plugin
147
+ */
148
+ $InferServerPlugin?: BetterAuthPlugin;
149
+ /**
150
+ * Custom actions
151
+ */
152
+ getActions?: ($fetch: BetterFetch, $store: ClientStore,
153
+ /**
154
+ * better-auth client options
155
+ */
156
+ options: BetterAuthClientOptions | undefined) => Record<string, any>;
157
+ /**
158
+ * State atoms that'll be resolved by each framework
159
+ * auth store.
160
+ */
161
+ getAtoms?: ($fetch: BetterFetch) => Record<string, Atom<any>>;
162
+ /**
163
+ * specify path methods for server plugin inferred
164
+ * endpoints to force a specific method.
165
+ */
166
+ pathMethods?: Record<string, "POST" | "GET">;
167
+ /**
168
+ * Better fetch plugins
169
+ */
170
+ fetchPlugins?: BetterFetchPlugin[];
171
+ /**
172
+ * a list of recaller based on a matcher function.
173
+ * The signal name needs to match a signal in this
174
+ * plugin or any plugin the user might have added.
175
+ */
176
+ atomListeners?: ClientAtomListener[];
112
177
  }
113
178
 
114
- export { LiteralUnion };
115
- export type { BetterAuthAdvancedOptions, BetterAuthMutators, GenerateIdFn };
179
+ export { AuthContext, BetterAuthOptions, LiteralString };
180
+ export type { BetterAuthClientOptions, BetterAuthClientPlugin, BetterAuthPlugin, ClientAtomListener, ClientStore };
package/dist/index.d.mts CHANGED
@@ -1,115 +1,180 @@
1
- import { L as LiteralUnion, M as Models } from './shared/core.CnvFgghY.mjs';
2
- export { a as LiteralString } from './shared/core.CnvFgghY.mjs';
3
- import { CookieOptions } from 'better-call';
1
+ import { L as LiteralString } from './shared/core.MjcDoj7R.mjs';
2
+ export { a as LiteralUnion } from './shared/core.MjcDoj7R.mjs';
3
+ import { A as AuthContext, B as BetterAuthOptions, a as AuthMiddleware } from './shared/core.CErFRCOZ.mjs';
4
+ export { b as BetterAuthAdvancedOptions, d as BetterAuthCookies, c as BetterAuthRateLimitOptions, G as GenerateIdFn, e as GenericEndpointContext, I as InternalAdapter } from './shared/core.CErFRCOZ.mjs';
5
+ import { Migration } from 'kysely';
6
+ import { Endpoint, Middleware, EndpointContext, InputContext } from 'better-call';
7
+ import { B as BetterAuthPluginDBSchema } from './shared/core.g9ACQ8v2.mjs';
8
+ import { BetterFetch, BetterFetchOption, BetterFetchPlugin } from '@better-fetch/fetch';
9
+ import { WritableAtom, Atom } from 'nanostores';
10
+ import 'better-sqlite3';
11
+ import './shared/core.g2ZbxAEV.mjs';
4
12
  import 'zod';
13
+ import 'bun:sqlite';
14
+ import 'node:sqlite';
15
+ import './social-providers/index.mjs';
16
+ import '@better-auth/core/oauth2';
17
+ import './shared/core.Bisb2Bdk.mjs';
18
+ import './shared/core.BwoNUcJQ.mjs';
19
+ import '@better-auth/core';
5
20
 
6
- type GenerateIdFn = (options: {
7
- model: LiteralUnion<Models, string>;
8
- size?: number;
9
- }) => string | false;
10
- type BetterAuthAdvancedOptions = {
21
+ type Awaitable<T> = T | Promise<T>;
22
+ type DeepPartial<T> = T extends Function ? T : T extends object ? {
23
+ [K in keyof T]?: DeepPartial<T[K]>;
24
+ } : T;
25
+ type HookEndpointContext = EndpointContext<string, any> & Omit<InputContext<string, any>, "method"> & {
26
+ context: AuthContext & {
27
+ returned?: unknown;
28
+ responseHeaders?: Headers;
29
+ };
30
+ headers?: Headers;
31
+ };
32
+ type BetterAuthPlugin = {
33
+ id: LiteralString;
11
34
  /**
12
- * Ip address configuration
35
+ * The init function is called when the plugin is initialized.
36
+ * You can return a new context or modify the existing context.
13
37
  */
14
- ipAddress?: {
15
- /**
16
- * List of headers to use for ip address
17
- *
18
- * Ip address is used for rate limiting and session tracking
19
- *
20
- * @example ["x-client-ip", "x-forwarded-for", "cf-connecting-ip"]
21
- *
22
- * @default
23
- * @link https://github.com/better-auth/better-auth/blob/main/packages/better-auth/src/utils/get-request-ip.ts#L8
24
- */
25
- ipAddressHeaders?: string[];
26
- /**
27
- * Disable ip tracking
28
- *
29
- * ⚠︎ This is a security risk and it may expose your application to abuse
30
- */
31
- disableIpTracking?: boolean;
38
+ init?: (ctx: AuthContext) => Awaitable<{
39
+ context?: DeepPartial<Omit<AuthContext, "options">>;
40
+ options?: Partial<BetterAuthOptions>;
41
+ }> | void | Promise<void>;
42
+ endpoints?: {
43
+ [key: string]: Endpoint;
44
+ };
45
+ middlewares?: {
46
+ path: string;
47
+ middleware: Middleware;
48
+ }[];
49
+ onRequest?: (request: Request, ctx: AuthContext) => Promise<{
50
+ response: Response;
51
+ } | {
52
+ request: Request;
53
+ } | void>;
54
+ onResponse?: (response: Response, ctx: AuthContext) => Promise<{
55
+ response: Response;
56
+ } | void>;
57
+ hooks?: {
58
+ before?: {
59
+ matcher: (context: HookEndpointContext) => boolean;
60
+ handler: AuthMiddleware;
61
+ }[];
62
+ after?: {
63
+ matcher: (context: HookEndpointContext) => boolean;
64
+ handler: AuthMiddleware;
65
+ }[];
32
66
  };
33
67
  /**
34
- * Use secure cookies
68
+ * Schema the plugin needs
69
+ *
70
+ * This will also be used to migrate the database. If the fields are dynamic from the plugins
71
+ * configuration each time the configuration is changed a new migration will be created.
35
72
  *
36
- * @default false
73
+ * NOTE: If you want to create migrations manually using
74
+ * migrations option or any other way you
75
+ * can disable migration per table basis.
76
+ *
77
+ * @example
78
+ * ```ts
79
+ * schema: {
80
+ * user: {
81
+ * fields: {
82
+ * email: {
83
+ * type: "string",
84
+ * },
85
+ * emailVerified: {
86
+ * type: "boolean",
87
+ * defaultValue: false,
88
+ * },
89
+ * },
90
+ * }
91
+ * } as AuthPluginSchema
92
+ * ```
37
93
  */
38
- useSecureCookies?: boolean;
94
+ schema?: BetterAuthPluginDBSchema;
39
95
  /**
40
- * Disable trusted origins check
96
+ * The migrations of the plugin. If you define schema that will automatically create
97
+ * migrations for you.
41
98
  *
42
- * ⚠︎ This is a security risk and it may expose your application to CSRF attacks
99
+ * ⚠️ Only uses this if you dont't want to use the schema option and you disabled migrations for
100
+ * the tables.
43
101
  */
44
- disableCSRFCheck?: boolean;
102
+ migrations?: Record<string, Migration>;
45
103
  /**
46
- * Configure cookies to be cross subdomains
104
+ * The options of the plugin
47
105
  */
48
- crossSubDomainCookies?: {
49
- /**
50
- * Enable cross subdomain cookies
51
- */
52
- enabled: boolean;
53
- /**
54
- * Additional cookies to be shared across subdomains
55
- */
56
- additionalCookies?: string[];
57
- /**
58
- * The domain to use for the cookies
59
- *
60
- * By default, the domain will be the root
61
- * domain from the base URL.
62
- */
63
- domain?: string;
64
- };
65
- cookies?: {
66
- [key: string]: {
67
- name?: string;
68
- attributes?: CookieOptions;
69
- };
70
- };
71
- defaultCookieAttributes?: CookieOptions;
106
+ options?: Record<string, any> | undefined;
72
107
  /**
73
- * Prefix for cookies. If a cookie name is provided
74
- * in cookies config, this will be overridden.
75
- *
76
- * @default
77
- * ```txt
78
- * "appName" -> which defaults to "better-auth"
79
- * ```
108
+ * types to be inferred
80
109
  */
81
- cookiePrefix?: string;
110
+ $Infer?: Record<string, any>;
82
111
  /**
83
- * Database configuration.
112
+ * The rate limit rules to apply to specific paths.
84
113
  */
85
- database?: {
86
- /**
87
- * The default number of records to return from the database
88
- * when using the `findMany` adapter method.
89
- *
90
- * @default 100
91
- */
92
- defaultFindManyLimit?: number;
93
- /**
94
- * If your database auto increments number ids, set this to `true`.
95
- *
96
- * Note: If enabled, we will not handle ID generation (including if you use `generateId`), and it would be expected that your database will provide the ID automatically.
97
- *
98
- * @default false
99
- */
100
- useNumberId?: boolean;
101
- /**
102
- * Custom generateId function.
103
- *
104
- * If not provided, random ids will be generated.
105
- * If set to false, the database's auto generated id will be used.
106
- */
107
- generateId?: GenerateIdFn | false;
108
- };
114
+ rateLimit?: {
115
+ window: number;
116
+ max: number;
117
+ pathMatcher: (path: string) => boolean;
118
+ }[];
119
+ /**
120
+ * The error codes returned by the plugin
121
+ */
122
+ $ERROR_CODES?: Record<string, string>;
109
123
  };
110
124
 
111
- interface BetterAuthMutators<O, C> {
125
+ interface ClientStore {
126
+ notify: (signal: string) => void;
127
+ listen: (signal: string, listener: () => void) => void;
128
+ atoms: Record<string, WritableAtom<any>>;
129
+ }
130
+ type ClientAtomListener = {
131
+ matcher: (path: string) => boolean;
132
+ signal: "$sessionSignal" | Omit<string, "$sessionSignal">;
133
+ };
134
+ interface BetterAuthClientOptions {
135
+ fetchOptions?: BetterFetchOption;
136
+ plugins?: BetterAuthClientPlugin[];
137
+ baseURL?: string;
138
+ basePath?: string;
139
+ disableDefaultFetchPlugins?: boolean;
140
+ $InferAuth?: BetterAuthOptions;
141
+ }
142
+ interface BetterAuthClientPlugin {
143
+ id: LiteralString;
144
+ /**
145
+ * only used for type inference. don't pass the
146
+ * actual plugin
147
+ */
148
+ $InferServerPlugin?: BetterAuthPlugin;
149
+ /**
150
+ * Custom actions
151
+ */
152
+ getActions?: ($fetch: BetterFetch, $store: ClientStore,
153
+ /**
154
+ * better-auth client options
155
+ */
156
+ options: BetterAuthClientOptions | undefined) => Record<string, any>;
157
+ /**
158
+ * State atoms that'll be resolved by each framework
159
+ * auth store.
160
+ */
161
+ getAtoms?: ($fetch: BetterFetch) => Record<string, Atom<any>>;
162
+ /**
163
+ * specify path methods for server plugin inferred
164
+ * endpoints to force a specific method.
165
+ */
166
+ pathMethods?: Record<string, "POST" | "GET">;
167
+ /**
168
+ * Better fetch plugins
169
+ */
170
+ fetchPlugins?: BetterFetchPlugin[];
171
+ /**
172
+ * a list of recaller based on a matcher function.
173
+ * The signal name needs to match a signal in this
174
+ * plugin or any plugin the user might have added.
175
+ */
176
+ atomListeners?: ClientAtomListener[];
112
177
  }
113
178
 
114
- export { LiteralUnion };
115
- export type { BetterAuthAdvancedOptions, BetterAuthMutators, GenerateIdFn };
179
+ export { AuthContext, BetterAuthOptions, LiteralString };
180
+ export type { BetterAuthClientOptions, BetterAuthClientPlugin, BetterAuthPlugin, ClientAtomListener, ClientStore };