@better-auth/core 1.3.28 → 1.4.0-beta.11

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 (157) hide show
  1. package/.turbo/turbo-build.log +81 -76
  2. package/dist/api/index.cjs +30 -0
  3. package/dist/api/index.d.cts +7 -0
  4. package/dist/api/index.d.ts +7 -0
  5. package/dist/api/index.js +26 -0
  6. package/dist/async_hooks/index.cjs +2 -26
  7. package/dist/async_hooks/index.d.cts +4 -7
  8. package/dist/async_hooks/index.d.ts +4 -7
  9. package/dist/async_hooks/index.js +3 -0
  10. package/dist/async_hooks-CaXONcb9.cjs +24 -0
  11. package/dist/async_hooks-CkLtIFa6.js +18 -0
  12. package/dist/chunk-CUT6urMc.cjs +30 -0
  13. package/dist/context/index.cjs +8 -0
  14. package/dist/context/index.d.cts +17 -0
  15. package/dist/context/index.d.ts +17 -0
  16. package/dist/context/index.js +4 -0
  17. package/dist/context-DAu9ytQl.cjs +85 -0
  18. package/dist/context-rhoB1CVr.js +56 -0
  19. package/dist/db/adapter/index.cjs +0 -2
  20. package/dist/db/adapter/index.d.cts +7 -14
  21. package/dist/db/adapter/index.d.ts +7 -14
  22. package/dist/db/adapter/index.js +1 -0
  23. package/dist/db/index.cjs +46 -69
  24. package/dist/db/index.d.cts +3 -39
  25. package/dist/db/index.d.ts +3 -39
  26. package/dist/db/index.js +61 -0
  27. package/dist/env/index.cjs +15 -311
  28. package/dist/env/index.d.cts +2 -36
  29. package/dist/env/index.d.ts +2 -36
  30. package/dist/env/index.js +3 -0
  31. package/dist/env-D1OdwBk9.cjs +330 -0
  32. package/dist/env-DzHiLVFb.js +246 -0
  33. package/dist/error/index.cjs +4 -43
  34. package/dist/error/index.d.cts +31 -29
  35. package/dist/error/index.d.ts +31 -29
  36. package/dist/error/index.js +4 -0
  37. package/dist/error-H6U5qGNP.js +45 -0
  38. package/dist/error-k9KM7GAb.cjs +56 -0
  39. package/dist/helper-DVgWo5zB.d.cts +6 -0
  40. package/dist/helper-Dm5AtPVS.d.ts +6 -0
  41. package/dist/index-BPsqLi68.d.ts +4410 -0
  42. package/dist/index-CgIE2ECh.d.cts +262 -0
  43. package/dist/index-ChlC5Vy3.d.ts +344 -0
  44. package/dist/index-Cmh0x42V.d.ts +262 -0
  45. package/dist/index-CsHMVqbX.d.ts +82 -0
  46. package/dist/index-DFwrZMma.d.cts +82 -0
  47. package/dist/index-OrTFOyAG.d.ts +1871 -0
  48. package/dist/index-_Oiv-VVr.d.cts +344 -0
  49. package/dist/index-ehsSkBxt.d.cts +4410 -0
  50. package/dist/index-yBChAjSS.d.cts +1871 -0
  51. package/dist/index.cjs +0 -2
  52. package/dist/index.d.cts +7 -180
  53. package/dist/index.d.ts +7 -180
  54. package/dist/index.js +1 -0
  55. package/dist/oauth2/index.cjs +12 -368
  56. package/dist/oauth2/index.d.cts +3 -100
  57. package/dist/oauth2/index.d.ts +3 -100
  58. package/dist/oauth2/index.js +3 -0
  59. package/dist/oauth2-D_FUKfC8.js +239 -0
  60. package/dist/oauth2-DqX_pPhp.cjs +302 -0
  61. package/dist/social-providers/index.cjs +2262 -2645
  62. package/dist/social-providers/index.d.cts +4 -3903
  63. package/dist/social-providers/index.d.ts +4 -3903
  64. package/dist/social-providers/index.js +2370 -0
  65. package/dist/utils/index.cjs +2 -6
  66. package/dist/utils/index.d.cts +4 -5
  67. package/dist/utils/index.d.ts +4 -5
  68. package/dist/utils/index.js +3 -0
  69. package/dist/utils-Bs-jKit4.cjs +13 -0
  70. package/dist/utils-Sn10glI8.js +7 -0
  71. package/package.json +35 -25
  72. package/src/api/index.ts +57 -0
  73. package/src/async_hooks/index.ts +1 -9
  74. package/src/context/endpoint-context.ts +32 -0
  75. package/src/context/index.ts +6 -0
  76. package/src/context/transaction.ts +63 -0
  77. package/src/db/index.ts +2 -0
  78. package/src/db/type.ts +1 -10
  79. package/src/env/color-depth.ts +4 -5
  80. package/src/error/codes.ts +1 -1
  81. package/src/social-providers/apple.ts +2 -2
  82. package/src/social-providers/atlassian.ts +4 -7
  83. package/src/social-providers/cognito.ts +4 -7
  84. package/src/social-providers/discord.ts +2 -5
  85. package/src/social-providers/dropbox.ts +2 -2
  86. package/src/social-providers/facebook.ts +3 -6
  87. package/src/social-providers/figma.ts +4 -7
  88. package/src/social-providers/github.ts +2 -2
  89. package/src/social-providers/gitlab.ts +2 -2
  90. package/src/social-providers/google.ts +4 -7
  91. package/src/social-providers/huggingface.ts +2 -2
  92. package/src/social-providers/kakao.ts +2 -2
  93. package/src/social-providers/kick.ts +2 -5
  94. package/src/social-providers/line.ts +2 -2
  95. package/src/social-providers/linear.ts +2 -2
  96. package/src/social-providers/linkedin.ts +2 -2
  97. package/src/social-providers/microsoft-entra-id.ts +3 -3
  98. package/src/social-providers/naver.ts +2 -2
  99. package/src/social-providers/notion.ts +2 -2
  100. package/src/social-providers/paypal.ts +3 -3
  101. package/src/social-providers/reddit.ts +2 -2
  102. package/src/social-providers/roblox.ts +2 -5
  103. package/src/social-providers/salesforce.ts +4 -7
  104. package/src/social-providers/slack.ts +2 -5
  105. package/src/social-providers/spotify.ts +2 -2
  106. package/src/social-providers/tiktok.ts +2 -5
  107. package/src/social-providers/twitch.ts +3 -3
  108. package/src/social-providers/twitter.ts +2 -2
  109. package/src/social-providers/vk.ts +2 -5
  110. package/src/social-providers/zoom.ts +2 -5
  111. package/src/types/context.ts +20 -99
  112. package/src/types/index.ts +1 -1
  113. package/src/types/init-options.ts +20 -22
  114. package/src/types/plugin.ts +3 -3
  115. package/{build.config.ts → tsdown.config.ts} +8 -11
  116. package/dist/async_hooks/index.d.mts +0 -10
  117. package/dist/async_hooks/index.mjs +0 -25
  118. package/dist/db/adapter/index.d.mts +0 -14
  119. package/dist/db/adapter/index.mjs +0 -1
  120. package/dist/db/index.d.mts +0 -39
  121. package/dist/db/index.mjs +0 -70
  122. package/dist/env/index.d.mts +0 -36
  123. package/dist/env/index.mjs +0 -297
  124. package/dist/error/index.d.mts +0 -33
  125. package/dist/error/index.mjs +0 -41
  126. package/dist/index.d.mts +0 -180
  127. package/dist/index.mjs +0 -1
  128. package/dist/middleware/index.cjs +0 -25
  129. package/dist/middleware/index.d.cts +0 -14
  130. package/dist/middleware/index.d.mts +0 -14
  131. package/dist/middleware/index.d.ts +0 -14
  132. package/dist/middleware/index.mjs +0 -21
  133. package/dist/oauth2/index.d.mts +0 -100
  134. package/dist/oauth2/index.mjs +0 -357
  135. package/dist/shared/core.BJPBStdk.d.ts +0 -1693
  136. package/dist/shared/core.Bl6TpxyD.d.mts +0 -181
  137. package/dist/shared/core.Bqe5IGAi.d.ts +0 -13
  138. package/dist/shared/core.BwoNUcJQ.d.cts +0 -53
  139. package/dist/shared/core.BwoNUcJQ.d.mts +0 -53
  140. package/dist/shared/core.BwoNUcJQ.d.ts +0 -53
  141. package/dist/shared/core.CajxAutx.d.cts +0 -143
  142. package/dist/shared/core.CajxAutx.d.mts +0 -143
  143. package/dist/shared/core.CajxAutx.d.ts +0 -143
  144. package/dist/shared/core.CkkLHQWc.d.mts +0 -1693
  145. package/dist/shared/core.DkdZ1o38.d.ts +0 -181
  146. package/dist/shared/core.Dl-70uns.d.cts +0 -84
  147. package/dist/shared/core.Dl-70uns.d.mts +0 -84
  148. package/dist/shared/core.Dl-70uns.d.ts +0 -84
  149. package/dist/shared/core.DyEdx0m7.d.cts +0 -181
  150. package/dist/shared/core.E9DfzGLz.d.mts +0 -13
  151. package/dist/shared/core.HqYn20Fi.d.cts +0 -13
  152. package/dist/shared/core.gYIBmdi1.d.cts +0 -1693
  153. package/dist/social-providers/index.d.mts +0 -3903
  154. package/dist/social-providers/index.mjs +0 -2743
  155. package/dist/utils/index.d.mts +0 -10
  156. package/dist/utils/index.mjs +0 -5
  157. package/src/middleware/index.ts +0 -33
@@ -0,0 +1,1871 @@
1
+ import { LiteralString, LiteralUnion } from "./helper-Dm5AtPVS.js";
2
+ import { Account, BetterAuthDBSchema, BetterAuthPluginDBSchema, DBFieldAttribute, DBPreservedModels, RateLimit, SecondaryStorage, Session, User, Verification } from "./index-Cmh0x42V.js";
3
+ import { OAuthProvider } from "./index-ChlC5Vy3.js";
4
+ import { SocialProviderList, SocialProviders } from "./index-BPsqLi68.js";
5
+ import { Logger, createLogger } from "./index-CsHMVqbX.js";
6
+ import * as better_call0 from "better-call";
7
+ import { CookieOptions, Endpoint, EndpointContext, EndpointOptions, InputContext, Middleware } from "better-call";
8
+ import { BetterFetch, BetterFetchOption, BetterFetchPlugin } from "@better-fetch/fetch";
9
+ import { Dialect, Kysely, Migration, MysqlPool, PostgresPool } from "kysely";
10
+ import { Database } from "better-sqlite3";
11
+ import { Database as Database$1 } from "bun:sqlite";
12
+ import { DatabaseSync } from "node:sqlite";
13
+ import { Atom, WritableAtom } from "nanostores";
14
+
15
+ //#region src/db/adapter/index.d.ts
16
+ type DBAdapterDebugLogOption = boolean | {
17
+ /**
18
+ * Useful when you want to log only certain conditions.
19
+ */
20
+ logCondition?: (() => boolean) | undefined;
21
+ create?: boolean;
22
+ update?: boolean;
23
+ updateMany?: boolean;
24
+ findOne?: boolean;
25
+ findMany?: boolean;
26
+ delete?: boolean;
27
+ deleteMany?: boolean;
28
+ count?: boolean;
29
+ } | {
30
+ /**
31
+ * Only used for adapter tests to show debug logs if a test fails.
32
+ *
33
+ * @deprecated Not actually deprecated. Doing this for IDEs to show this option at the very bottom and stop end-users from using this.
34
+ */
35
+ isRunningAdapterTests: boolean;
36
+ };
37
+ type DBAdapterSchemaCreation = {
38
+ /**
39
+ * Code to be inserted into the file
40
+ */
41
+ code: string;
42
+ /**
43
+ * Path to the file, including the file name and extension.
44
+ * Relative paths are supported, with the current working directory of the developer's project as the base.
45
+ */
46
+ path: string;
47
+ /**
48
+ * Append the file if it already exists.
49
+ * Note: This will not apply if `overwrite` is set to true.
50
+ */
51
+ append?: boolean;
52
+ /**
53
+ * Overwrite the file if it already exists
54
+ */
55
+ overwrite?: boolean;
56
+ };
57
+ interface DBAdapterFactoryConfig<Options extends BetterAuthOptions = BetterAuthOptions> {
58
+ /**
59
+ * Use plural table names.
60
+ *
61
+ * All tables will be named with an `s` at the end.
62
+ *
63
+ * @default false
64
+ */
65
+ usePlural?: boolean;
66
+ /**
67
+ * Enable debug logs.
68
+ *
69
+ * @default false
70
+ */
71
+ debugLogs?: DBAdapterDebugLogOption;
72
+ /**
73
+ * Name of the adapter.
74
+ *
75
+ * This is used to identify the adapter in the debug logs.
76
+ *
77
+ * @default `adapterId`
78
+ */
79
+ adapterName?: string;
80
+ /**
81
+ * Adapter id
82
+ */
83
+ adapterId: string;
84
+ /**
85
+ * If the database supports numeric ids, set this to `true`.
86
+ *
87
+ * @default true
88
+ */
89
+ supportsNumericIds?: boolean;
90
+ /**
91
+ * If the database doesn't support JSON columns, set this to `false`.
92
+ *
93
+ * We will handle the translation between using `JSON` columns, and saving `string`s to the database.
94
+ *
95
+ * @default false
96
+ */
97
+ supportsJSON?: boolean;
98
+ /**
99
+ * If the database doesn't support dates, set this to `false`.
100
+ *
101
+ * We will handle the translation between using `Date` objects, and saving `string`s to the database.
102
+ *
103
+ * @default true
104
+ */
105
+ supportsDates?: boolean;
106
+ /**
107
+ * If the database doesn't support booleans, set this to `false`.
108
+ *
109
+ * We will handle the translation between using `boolean`s, and saving `0`s and `1`s to the database.
110
+ *
111
+ * @default true
112
+ */
113
+ supportsBooleans?: boolean;
114
+ /**
115
+ * Execute multiple operations in a transaction.
116
+ *
117
+ * If the database doesn't support transactions, set this to `false` and operations will be executed sequentially.
118
+ *
119
+ * @default false
120
+ */
121
+ transaction?: false | (<R>(callback: (trx: DBTransactionAdapter<Options>) => Promise<R>) => Promise<R>);
122
+ /**
123
+ * Disable id generation for the `create` method.
124
+ *
125
+ * This is useful for databases that don't support custom id values and would auto-generate them for you.
126
+ *
127
+ * @default false
128
+ */
129
+ disableIdGeneration?: boolean;
130
+ /**
131
+ * Map the keys of the input data.
132
+ *
133
+ * This is useful for databases that expect a different key name for a given situation.
134
+ *
135
+ * For example, MongoDB uses `_id` while in Better-Auth we use `id`.
136
+ *
137
+ *
138
+ * @example
139
+ * Each key represents the old key to replace.
140
+ * The value represents the new key
141
+ *
142
+ * This can be a partial object that only transforms some keys.
143
+ *
144
+ * ```ts
145
+ * mapKeysTransformInput: {
146
+ * id: "_id" // We want to replace `id` to `_id` to save into MongoDB
147
+ * }
148
+ * ```
149
+ */
150
+ mapKeysTransformInput?: Record<string, string>;
151
+ /**
152
+ * Map the keys of the output data.
153
+ *
154
+ * This is useful for databases that expect a different key name for a given situation.
155
+ *
156
+ * For example, MongoDB uses `_id` while in Better-Auth we use `id`.
157
+ *
158
+ * @example
159
+ * Each key represents the old key to replace.
160
+ * The value represents the new key
161
+ *
162
+ * This can be a partial object that only transforms some keys.
163
+ *
164
+ * ```ts
165
+ * mapKeysTransformOutput: {
166
+ * _id: "id" // In MongoDB, we save `id` as `_id`. So we want to replace `_id` with `id` when we get the data back.
167
+ * }
168
+ * ```
169
+ */
170
+ mapKeysTransformOutput?: Record<string, string>;
171
+ /**
172
+ * Custom transform input function.
173
+ *
174
+ * This function is used to transform the input data before it is saved to the database.
175
+ */
176
+ customTransformInput?: (props: {
177
+ data: any;
178
+ /**
179
+ * The fields of the model.
180
+ */
181
+ fieldAttributes: DBFieldAttribute;
182
+ /**
183
+ * The field to transform.
184
+ */
185
+ field: string;
186
+ /**
187
+ * The action which was called from the adapter.
188
+ */
189
+ action: "create" | "update";
190
+ /**
191
+ * The model name.
192
+ */
193
+ model: string;
194
+ /**
195
+ * The schema of the user's Better-Auth instance.
196
+ */
197
+ schema: BetterAuthDBSchema;
198
+ /**
199
+ * The options of the user's Better-Auth instance.
200
+ */
201
+ options: Options;
202
+ }) => any;
203
+ /**
204
+ * Custom transform output function.
205
+ *
206
+ * This function is used to transform the output data before it is returned to the user.
207
+ */
208
+ customTransformOutput?: (props: {
209
+ data: any;
210
+ /**
211
+ * The fields of the model.
212
+ */
213
+ fieldAttributes: DBFieldAttribute;
214
+ /**
215
+ * The field to transform.
216
+ */
217
+ field: string;
218
+ /**
219
+ * The fields to select.
220
+ */
221
+ select: string[];
222
+ /**
223
+ * The model name.
224
+ */
225
+ model: string;
226
+ /**
227
+ * The schema of the user's Better-Auth instance.
228
+ */
229
+ schema: BetterAuthDBSchema;
230
+ /**
231
+ * The options of the user's Better-Auth instance.
232
+ */
233
+ options: Options;
234
+ }) => any;
235
+ /**
236
+ * Custom ID generator function.
237
+ *
238
+ * By default, we can handle ID generation for you, however if the database your adapter is for only supports a specific custom id generation,
239
+ * then you can use this function to generate your own IDs.
240
+ *
241
+ *
242
+ * Notes:
243
+ * - If the user enabled `useNumberId`, then this option will be ignored. Unless this adapter config has `supportsNumericIds` set to `false`.
244
+ * - If `generateId` is `false` in the user's Better-Auth config, then this option will be ignored.
245
+ * - If `generateId` is a function, then it will override this option.
246
+ *
247
+ * @example
248
+ *
249
+ * ```ts
250
+ * customIdGenerator: ({ model }) => {
251
+ * return "my-super-unique-id";
252
+ * }
253
+ * ```
254
+ */
255
+ customIdGenerator?: (props: {
256
+ model: string;
257
+ }) => string;
258
+ /**
259
+ * Whether to disable the transform output.
260
+ * Do not use this option unless you know what you are doing.
261
+ * @default false
262
+ */
263
+ disableTransformOutput?: boolean;
264
+ /**
265
+ * Whether to disable the transform input.
266
+ * Do not use this option unless you know what you are doing.
267
+ * @default false
268
+ */
269
+ disableTransformInput?: boolean;
270
+ }
271
+ type Where = {
272
+ /**
273
+ * @default eq
274
+ */
275
+ operator?: "eq" | "ne" | "lt" | "lte" | "gt" | "gte" | "in" | "not_in" | "contains" | "starts_with" | "ends_with";
276
+ value: string | number | boolean | string[] | number[] | Date | null;
277
+ field: string;
278
+ /**
279
+ * @default AND
280
+ */
281
+ connector?: "AND" | "OR";
282
+ };
283
+ type DBTransactionAdapter<Options extends BetterAuthOptions = BetterAuthOptions> = Omit<DBAdapter<Options>, "transaction">;
284
+ type DBAdapter<Options extends BetterAuthOptions = BetterAuthOptions> = {
285
+ id: string;
286
+ create: <T extends Record<string, any>, R = T>(data: {
287
+ model: string;
288
+ data: Omit<T, "id">;
289
+ select?: string[];
290
+ /**
291
+ * By default, any `id` provided in `data` will be ignored.
292
+ *
293
+ * If you want to force the `id` to be the same as the `data.id`, set this to `true`.
294
+ */
295
+ forceAllowId?: boolean;
296
+ }) => Promise<R>;
297
+ findOne: <T>(data: {
298
+ model: string;
299
+ where: Where[];
300
+ select?: string[];
301
+ }) => Promise<T | null>;
302
+ findMany: <T>(data: {
303
+ model: string;
304
+ where?: Where[];
305
+ limit?: number;
306
+ sortBy?: {
307
+ field: string;
308
+ direction: "asc" | "desc";
309
+ };
310
+ offset?: number;
311
+ }) => Promise<T[]>;
312
+ count: (data: {
313
+ model: string;
314
+ where?: Where[];
315
+ }) => Promise<number>;
316
+ /**
317
+ * ⚠︎ Update may not return the updated data
318
+ * if multiple where clauses are provided
319
+ */
320
+ update: <T>(data: {
321
+ model: string;
322
+ where: Where[];
323
+ update: Record<string, any>;
324
+ }) => Promise<T | null>;
325
+ updateMany: (data: {
326
+ model: string;
327
+ where: Where[];
328
+ update: Record<string, any>;
329
+ }) => Promise<number>;
330
+ delete: <T>(data: {
331
+ model: string;
332
+ where: Where[];
333
+ }) => Promise<void>;
334
+ deleteMany: (data: {
335
+ model: string;
336
+ where: Where[];
337
+ }) => Promise<number>;
338
+ /**
339
+ * Execute multiple operations in a transaction.
340
+ * If the adapter doesn't support transactions, operations will be executed sequentially.
341
+ */
342
+ transaction: <R>(callback: (trx: DBTransactionAdapter<Options>) => Promise<R>) => Promise<R>;
343
+ /**
344
+ *
345
+ * @param options
346
+ * @param file - file path if provided by the user
347
+ */
348
+ createSchema?: (options: Options, file?: string) => Promise<DBAdapterSchemaCreation>;
349
+ options?: {
350
+ adapterConfig: DBAdapterFactoryConfig<Options>;
351
+ } & CustomAdapter["options"];
352
+ };
353
+ type CleanedWhere = Required<Where>;
354
+ interface CustomAdapter {
355
+ create: <T extends Record<string, any>>({
356
+ data,
357
+ model,
358
+ select
359
+ }: {
360
+ model: string;
361
+ data: T;
362
+ select?: string[];
363
+ }) => Promise<T>;
364
+ update: <T>(data: {
365
+ model: string;
366
+ where: CleanedWhere[];
367
+ update: T;
368
+ }) => Promise<T | null>;
369
+ updateMany: (data: {
370
+ model: string;
371
+ where: CleanedWhere[];
372
+ update: Record<string, any>;
373
+ }) => Promise<number>;
374
+ findOne: <T>({
375
+ model,
376
+ where,
377
+ select
378
+ }: {
379
+ model: string;
380
+ where: CleanedWhere[];
381
+ select?: string[];
382
+ }) => Promise<T | null>;
383
+ findMany: <T>({
384
+ model,
385
+ where,
386
+ limit,
387
+ sortBy,
388
+ offset
389
+ }: {
390
+ model: string;
391
+ where?: CleanedWhere[];
392
+ limit: number;
393
+ sortBy?: {
394
+ field: string;
395
+ direction: "asc" | "desc";
396
+ };
397
+ offset?: number;
398
+ }) => Promise<T[]>;
399
+ delete: ({
400
+ model,
401
+ where
402
+ }: {
403
+ model: string;
404
+ where: CleanedWhere[];
405
+ }) => Promise<void>;
406
+ deleteMany: ({
407
+ model,
408
+ where
409
+ }: {
410
+ model: string;
411
+ where: CleanedWhere[];
412
+ }) => Promise<number>;
413
+ count: ({
414
+ model,
415
+ where
416
+ }: {
417
+ model: string;
418
+ where?: CleanedWhere[];
419
+ }) => Promise<number>;
420
+ createSchema?: (props: {
421
+ /**
422
+ * The file the user may have passed in to the `generate` command as the expected schema file output path.
423
+ */
424
+ file?: string;
425
+ /**
426
+ * The tables from the user's Better-Auth instance schema.
427
+ */
428
+ tables: BetterAuthDBSchema;
429
+ }) => Promise<DBAdapterSchemaCreation>;
430
+ /**
431
+ * Your adapter's options.
432
+ */
433
+ options?: Record<string, any> | undefined;
434
+ }
435
+ interface DBAdapterInstance<Options extends BetterAuthOptions = BetterAuthOptions> {
436
+ (options: BetterAuthOptions): DBAdapter<Options>;
437
+ }
438
+ //#endregion
439
+ //#region src/types/cookie.d.ts
440
+ type BetterAuthCookies = {
441
+ sessionToken: {
442
+ name: string;
443
+ options: CookieOptions;
444
+ };
445
+ sessionData: {
446
+ name: string;
447
+ options: CookieOptions;
448
+ };
449
+ dontRememberToken: {
450
+ name: string;
451
+ options: CookieOptions;
452
+ };
453
+ };
454
+ //#endregion
455
+ //#region src/types/context.d.ts
456
+ type GenericEndpointContext<Options extends BetterAuthOptions = BetterAuthOptions> = EndpointContext<string, any> & {
457
+ context: AuthContext<Options>;
458
+ };
459
+ interface InternalAdapter<Options extends BetterAuthOptions = BetterAuthOptions> {
460
+ createOAuthUser(user: Omit<User, "id" | "createdAt" | "updatedAt">, account: Omit<Account, "userId" | "id" | "createdAt" | "updatedAt"> & Partial<Account>): Promise<{
461
+ user: User;
462
+ account: Account;
463
+ }>;
464
+ createUser<T extends Record<string, any>>(user: Omit<User, "id" | "createdAt" | "updatedAt" | "emailVerified"> & Partial<User> & Record<string, any>): Promise<T & User>;
465
+ createAccount<T extends Record<string, any>>(account: Omit<Account, "id" | "createdAt" | "updatedAt"> & Partial<Account> & T): Promise<T & Account>;
466
+ listSessions(userId: string): Promise<Session[]>;
467
+ listUsers(limit?: number, offset?: number, sortBy?: {
468
+ field: string;
469
+ direction: "asc" | "desc";
470
+ }, where?: Where[]): Promise<User[]>;
471
+ countTotalUsers(where?: Where[]): Promise<number>;
472
+ deleteUser(userId: string): Promise<void>;
473
+ createSession(userId: string, dontRememberMe?: boolean, override?: Partial<Session> & Record<string, any>, overrideAll?: boolean): Promise<Session>;
474
+ findSession(token: string): Promise<{
475
+ session: Session & Record<string, any>;
476
+ user: User & Record<string, any>;
477
+ } | null>;
478
+ findSessions(sessionTokens: string[]): Promise<{
479
+ session: Session;
480
+ user: User;
481
+ }[]>;
482
+ updateSession(sessionToken: string, session: Partial<Session> & Record<string, any>): Promise<Session | null>;
483
+ deleteSession(token: string): Promise<void>;
484
+ deleteAccounts(userId: string): Promise<void>;
485
+ deleteAccount(accountId: string): Promise<void>;
486
+ deleteSessions(userIdOrSessionTokens: string | string[]): Promise<void>;
487
+ findOAuthUser(email: string, accountId: string, providerId: string): Promise<{
488
+ user: User;
489
+ accounts: Account[];
490
+ } | null>;
491
+ findUserByEmail(email: string, options?: {
492
+ includeAccounts: boolean;
493
+ }): Promise<{
494
+ user: User;
495
+ accounts: Account[];
496
+ } | null>;
497
+ findUserById(userId: string): Promise<User | null>;
498
+ linkAccount(account: Omit<Account, "id" | "createdAt" | "updatedAt"> & Partial<Account>): Promise<Account>;
499
+ updateUser(userId: string, data: Partial<User> & Record<string, any>): Promise<any>;
500
+ updateUserByEmail(email: string, data: Partial<User & Record<string, any>>): Promise<User>;
501
+ updatePassword(userId: string, password: string): Promise<void>;
502
+ findAccounts(userId: string): Promise<Account[]>;
503
+ findAccount(accountId: string): Promise<Account | null>;
504
+ findAccountByProviderId(accountId: string, providerId: string): Promise<Account | null>;
505
+ findAccountByUserId(userId: string): Promise<Account[]>;
506
+ updateAccount(id: string, data: Partial<Account>): Promise<Account>;
507
+ createVerificationValue(data: Omit<Verification, "createdAt" | "id" | "updatedAt"> & Partial<Verification>): Promise<Verification>;
508
+ findVerificationValue(identifier: string): Promise<Verification | null>;
509
+ deleteVerificationValue(id: string): Promise<void>;
510
+ deleteVerificationByIdentifier(identifier: string): Promise<void>;
511
+ updateVerificationValue(id: string, data: Partial<Verification>): Promise<Verification>;
512
+ }
513
+ type CreateCookieGetterFn = (cookieName: string, overrideAttributes?: Partial<CookieOptions>) => {
514
+ name: string;
515
+ attributes: CookieOptions;
516
+ };
517
+ type CheckPasswordFn<Options extends BetterAuthOptions = BetterAuthOptions> = (userId: string, ctx: GenericEndpointContext<Options>) => Promise<boolean>;
518
+ type AuthContext<Options extends BetterAuthOptions = BetterAuthOptions> = {
519
+ options: Options;
520
+ appName: string;
521
+ baseURL: string;
522
+ trustedOrigins: string[];
523
+ oauthConfig?: {
524
+ /**
525
+ * This is dangerous and should only be used in dev or staging environments.
526
+ */
527
+ skipStateCookieCheck?: boolean;
528
+ };
529
+ /**
530
+ * New session that will be set after the request
531
+ * meaning: there is a `set-cookie` header that will set
532
+ * the session cookie. This is the fetched session. And it's set
533
+ * by `setNewSession` method.
534
+ */
535
+ newSession: {
536
+ session: Session & Record<string, any>;
537
+ user: User & Record<string, any>;
538
+ } | null;
539
+ session: {
540
+ session: Session & Record<string, any>;
541
+ user: User & Record<string, any>;
542
+ } | null;
543
+ setNewSession: (session: {
544
+ session: Session & Record<string, any>;
545
+ user: User & Record<string, any>;
546
+ } | null) => void;
547
+ socialProviders: OAuthProvider[];
548
+ authCookies: BetterAuthCookies;
549
+ logger: ReturnType<typeof createLogger>;
550
+ rateLimit: {
551
+ enabled: boolean;
552
+ window: number;
553
+ max: number;
554
+ storage: "memory" | "database" | "secondary-storage";
555
+ } & BetterAuthRateLimitOptions;
556
+ adapter: DBAdapter<Options>;
557
+ internalAdapter: InternalAdapter<Options>;
558
+ createAuthCookie: CreateCookieGetterFn;
559
+ secret: string;
560
+ sessionConfig: {
561
+ updateAge: number;
562
+ expiresIn: number;
563
+ freshAge: number;
564
+ };
565
+ generateId: (options: {
566
+ model: LiteralUnion<DBPreservedModels, string>;
567
+ size?: number;
568
+ }) => string | false;
569
+ secondaryStorage: SecondaryStorage | undefined;
570
+ password: {
571
+ hash: (password: string) => Promise<string>;
572
+ verify: (data: {
573
+ password: string;
574
+ hash: string;
575
+ }) => Promise<boolean>;
576
+ config: {
577
+ minPasswordLength: number;
578
+ maxPasswordLength: number;
579
+ };
580
+ checkPassword: CheckPasswordFn<Options>;
581
+ };
582
+ tables: BetterAuthDBSchema;
583
+ runMigrations: () => Promise<void>;
584
+ publishTelemetry: (event: {
585
+ type: string;
586
+ anonymousId?: string;
587
+ payload: Record<string, any>;
588
+ }) => Promise<void>;
589
+ };
590
+ //#endregion
591
+ //#region src/types/init-options.d.ts
592
+ type KyselyDatabaseType = "postgres" | "mysql" | "sqlite" | "mssql";
593
+ type OmitId<T extends {
594
+ id: unknown;
595
+ }> = Omit<T, "id">;
596
+ type Optional<T> = { [P in keyof T]?: T[P] | undefined };
597
+ type GenerateIdFn = (options: {
598
+ model: LiteralUnion<DBPreservedModels, string>;
599
+ size?: number;
600
+ }) => string | false;
601
+ type BetterAuthRateLimitOptions = {
602
+ /**
603
+ * By default, rate limiting is only
604
+ * enabled on production.
605
+ */
606
+ enabled?: boolean;
607
+ /**
608
+ * Default window to use for rate limiting. The value
609
+ * should be in seconds.
610
+ *
611
+ * @default 10 seconds
612
+ */
613
+ window?: number;
614
+ /**
615
+ * The default maximum number of requests allowed within the window.
616
+ *
617
+ * @default 100 requests
618
+ */
619
+ max?: number;
620
+ /**
621
+ * Custom rate limit rules to apply to
622
+ * specific paths.
623
+ */
624
+ customRules?: {
625
+ [key: string]: {
626
+ /**
627
+ * The window to use for the custom rule.
628
+ */
629
+ window: number;
630
+ /**
631
+ * The maximum number of requests allowed within the window.
632
+ */
633
+ max: number;
634
+ } | false | ((request: Request) => {
635
+ window: number;
636
+ max: number;
637
+ } | false | Promise<{
638
+ window: number;
639
+ max: number;
640
+ } | false>);
641
+ };
642
+ /**
643
+ * Storage configuration
644
+ *
645
+ * By default, rate limiting is stored in memory. If you passed a
646
+ * secondary storage, rate limiting will be stored in the secondary
647
+ * storage.
648
+ *
649
+ * @default "memory"
650
+ */
651
+ storage?: "memory" | "database" | "secondary-storage";
652
+ /**
653
+ * If database is used as storage, the name of the table to
654
+ * use for rate limiting.
655
+ *
656
+ * @default "rateLimit"
657
+ */
658
+ modelName?: string;
659
+ /**
660
+ * Custom field names for the rate limit table
661
+ */
662
+ fields?: Record<keyof RateLimit, string>;
663
+ /**
664
+ * custom storage configuration.
665
+ *
666
+ * NOTE: If custom storage is used storage
667
+ * is ignored
668
+ */
669
+ customStorage?: {
670
+ get: (key: string) => Promise<RateLimit | undefined>;
671
+ set: (key: string, value: RateLimit) => Promise<void>;
672
+ };
673
+ };
674
+ type BetterAuthAdvancedOptions = {
675
+ /**
676
+ * Ip address configuration
677
+ */
678
+ ipAddress?: {
679
+ /**
680
+ * List of headers to use for ip address
681
+ *
682
+ * Ip address is used for rate limiting and session tracking
683
+ *
684
+ * @example ["x-client-ip", "x-forwarded-for", "cf-connecting-ip"]
685
+ *
686
+ * @default
687
+ * @link https://github.com/better-auth/better-auth/blob/main/packages/better-auth/src/utils/get-request-ip.ts#L8
688
+ */
689
+ ipAddressHeaders?: string[];
690
+ /**
691
+ * Disable ip tracking
692
+ *
693
+ * ⚠︎ This is a security risk and it may expose your application to abuse
694
+ */
695
+ disableIpTracking?: boolean;
696
+ };
697
+ /**
698
+ * Use secure cookies
699
+ *
700
+ * @default false
701
+ */
702
+ useSecureCookies?: boolean;
703
+ /**
704
+ * Disable trusted origins check
705
+ *
706
+ * ⚠︎ This is a security risk and it may expose your application to CSRF attacks
707
+ */
708
+ disableCSRFCheck?: boolean;
709
+ /**
710
+ * Configure cookies to be cross subdomains
711
+ */
712
+ crossSubDomainCookies?: {
713
+ /**
714
+ * Enable cross subdomain cookies
715
+ */
716
+ enabled: boolean;
717
+ /**
718
+ * Additional cookies to be shared across subdomains
719
+ */
720
+ additionalCookies?: string[];
721
+ /**
722
+ * The domain to use for the cookies
723
+ *
724
+ * By default, the domain will be the root
725
+ * domain from the base URL.
726
+ */
727
+ domain?: string;
728
+ };
729
+ cookies?: {
730
+ [key: string]: {
731
+ name?: string;
732
+ attributes?: CookieOptions;
733
+ };
734
+ };
735
+ defaultCookieAttributes?: CookieOptions;
736
+ /**
737
+ * Prefix for cookies. If a cookie name is provided
738
+ * in cookies config, this will be overridden.
739
+ *
740
+ * @default
741
+ * ```txt
742
+ * "appName" -> which defaults to "better-auth"
743
+ * ```
744
+ */
745
+ cookiePrefix?: string;
746
+ /**
747
+ * Database configuration.
748
+ */
749
+ database?: {
750
+ /**
751
+ * The default number of records to return from the database
752
+ * when using the `findMany` adapter method.
753
+ *
754
+ * @default 100
755
+ */
756
+ defaultFindManyLimit?: number;
757
+ /**
758
+ * If your database auto increments number ids, set this to `true`.
759
+ *
760
+ * 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.
761
+ *
762
+ * @default false
763
+ */
764
+ useNumberId?: boolean;
765
+ /**
766
+ * Custom generateId function.
767
+ *
768
+ * If not provided, random ids will be generated.
769
+ * If set to false, the database's auto generated id will be used.
770
+ */
771
+ generateId?: GenerateIdFn | false;
772
+ };
773
+ };
774
+ type BetterAuthOptions = {
775
+ /**
776
+ * The name of the application
777
+ *
778
+ * process.env.APP_NAME
779
+ *
780
+ * @default "Better Auth"
781
+ */
782
+ appName?: string;
783
+ /**
784
+ * Base URL for the Better Auth. This is typically the
785
+ * root URL where your application server is hosted.
786
+ * If not explicitly set,
787
+ * the system will check the following environment variable:
788
+ *
789
+ * process.env.BETTER_AUTH_URL
790
+ */
791
+ baseURL?: string;
792
+ /**
793
+ * Base path for the Better Auth. This is typically
794
+ * the path where the
795
+ * Better Auth routes are mounted.
796
+ *
797
+ * @default "/api/auth"
798
+ */
799
+ basePath?: string;
800
+ /**
801
+ * The secret to use for encryption,
802
+ * signing and hashing.
803
+ *
804
+ * By default Better Auth will look for
805
+ * the following environment variables:
806
+ * process.env.BETTER_AUTH_SECRET,
807
+ * process.env.AUTH_SECRET
808
+ * If none of these environment
809
+ * variables are set,
810
+ * it will default to
811
+ * "better-auth-secret-123456789".
812
+ *
813
+ * on production if it's not set
814
+ * it will throw an error.
815
+ *
816
+ * you can generate a good secret
817
+ * using the following command:
818
+ * @example
819
+ * ```bash
820
+ * openssl rand -base64 32
821
+ * ```
822
+ */
823
+ secret?: string;
824
+ /**
825
+ * Database configuration
826
+ */
827
+ database?: PostgresPool | MysqlPool | Database | Dialect | DBAdapterInstance | Database$1 | DatabaseSync | {
828
+ dialect: Dialect;
829
+ type: KyselyDatabaseType;
830
+ /**
831
+ * casing for table names
832
+ *
833
+ * @default "camel"
834
+ */
835
+ casing?: "snake" | "camel";
836
+ /**
837
+ * Enable debug logs for the adapter
838
+ *
839
+ * @default false
840
+ */
841
+ debugLogs?: DBAdapterDebugLogOption;
842
+ /**
843
+ * Whether to execute multiple operations in a transaction.
844
+ * If the database doesn't support transactions,
845
+ * set this to `false` and operations will be executed sequentially.
846
+ * @default true
847
+ */
848
+ transaction?: boolean;
849
+ } | {
850
+ /**
851
+ * Kysely instance
852
+ */
853
+ db: Kysely<any>;
854
+ /**
855
+ * Database type between postgres, mysql and sqlite
856
+ */
857
+ type: KyselyDatabaseType;
858
+ /**
859
+ * casing for table names
860
+ *
861
+ * @default "camel"
862
+ */
863
+ casing?: "snake" | "camel";
864
+ /**
865
+ * Enable debug logs for the adapter
866
+ *
867
+ * @default false
868
+ */
869
+ debugLogs?: DBAdapterDebugLogOption;
870
+ /**
871
+ * Whether to execute multiple operations in a transaction.
872
+ * If the database doesn't support transactions,
873
+ * set this to `false` and operations will be executed sequentially.
874
+ * @default true
875
+ */
876
+ transaction?: boolean;
877
+ };
878
+ /**
879
+ * Secondary storage configuration
880
+ *
881
+ * This is used to store session and rate limit data.
882
+ */
883
+ secondaryStorage?: SecondaryStorage;
884
+ /**
885
+ * Email verification configuration
886
+ */
887
+ emailVerification?: {
888
+ /**
889
+ * Send a verification email
890
+ * @param data the data object
891
+ * @param request the request object
892
+ */
893
+ sendVerificationEmail?: (
894
+ /**
895
+ * @param user the user to send the
896
+ * verification email to
897
+ * @param url the URL to send the verification email to
898
+ * it contains the token as well
899
+ * @param token the token to send the verification email to
900
+ */
901
+ data: {
902
+ user: User;
903
+ url: string;
904
+ token: string;
905
+ },
906
+ /**
907
+ * The request object
908
+ */
909
+ request?: Request) => Promise<void>;
910
+ /**
911
+ * Send a verification email automatically
912
+ * after sign up
913
+ *
914
+ * @default false
915
+ */
916
+ sendOnSignUp?: boolean;
917
+ /**
918
+ * Send a verification email automatically
919
+ * on sign in when the user's email is not verified
920
+ *
921
+ * @default false
922
+ */
923
+ sendOnSignIn?: boolean;
924
+ /**
925
+ * Auto signin the user after they verify their email
926
+ */
927
+ autoSignInAfterVerification?: boolean;
928
+ /**
929
+ * Number of seconds the verification token is
930
+ * valid for.
931
+ * @default 3600 seconds (1 hour)
932
+ */
933
+ expiresIn?: number;
934
+ /**
935
+ * A function that is called when a user verifies their email
936
+ * @param user the user that verified their email
937
+ * @param request the request object
938
+ */
939
+ onEmailVerification?: (user: User, request?: Request) => Promise<void>;
940
+ /**
941
+ * A function that is called when a user's email is updated to verified
942
+ * @param user the user that verified their email
943
+ * @param request the request object
944
+ */
945
+ afterEmailVerification?: (user: User, request?: Request) => Promise<void>;
946
+ };
947
+ /**
948
+ * Email and password authentication
949
+ */
950
+ emailAndPassword?: {
951
+ /**
952
+ * Enable email and password authentication
953
+ *
954
+ * @default false
955
+ */
956
+ enabled: boolean;
957
+ /**
958
+ * Disable email and password sign up
959
+ *
960
+ * @default false
961
+ */
962
+ disableSignUp?: boolean;
963
+ /**
964
+ * Require email verification before a session
965
+ * can be created for the user.
966
+ *
967
+ * if the user is not verified, the user will not be able to sign in
968
+ * and on sign in attempts, the user will be prompted to verify their email.
969
+ */
970
+ requireEmailVerification?: boolean;
971
+ /**
972
+ * The maximum length of the password.
973
+ *
974
+ * @default 128
975
+ */
976
+ maxPasswordLength?: number;
977
+ /**
978
+ * The minimum length of the password.
979
+ *
980
+ * @default 8
981
+ */
982
+ minPasswordLength?: number;
983
+ /**
984
+ * send reset password
985
+ */
986
+ sendResetPassword?: (
987
+ /**
988
+ * @param user the user to send the
989
+ * reset password email to
990
+ * @param url the URL to send the reset password email to
991
+ * @param token the token to send to the user (could be used instead of sending the url
992
+ * if you need to redirect the user to custom route)
993
+ */
994
+ data: {
995
+ user: User;
996
+ url: string;
997
+ token: string;
998
+ },
999
+ /**
1000
+ * The request object
1001
+ */
1002
+ request?: Request) => Promise<void>;
1003
+ /**
1004
+ * Number of seconds the reset password token is
1005
+ * valid for.
1006
+ * @default 1 hour (60 * 60)
1007
+ */
1008
+ resetPasswordTokenExpiresIn?: number;
1009
+ /**
1010
+ * A callback function that is triggered
1011
+ * when a user's password is changed successfully.
1012
+ */
1013
+ onPasswordReset?: (data: {
1014
+ user: User;
1015
+ }, request?: Request) => Promise<void>;
1016
+ /**
1017
+ * Password hashing and verification
1018
+ *
1019
+ * By default Scrypt is used for password hashing and
1020
+ * verification. You can provide your own hashing and
1021
+ * verification function. if you want to use a
1022
+ * different algorithm.
1023
+ */
1024
+ password?: {
1025
+ hash?: (password: string) => Promise<string>;
1026
+ verify?: (data: {
1027
+ hash: string;
1028
+ password: string;
1029
+ }) => Promise<boolean>;
1030
+ };
1031
+ /**
1032
+ * Automatically sign in the user after sign up
1033
+ *
1034
+ * @default true
1035
+ */
1036
+ autoSignIn?: boolean;
1037
+ /**
1038
+ * Whether to revoke all other sessions when resetting password
1039
+ * @default false
1040
+ */
1041
+ revokeSessionsOnPasswordReset?: boolean;
1042
+ };
1043
+ /**
1044
+ * list of social providers
1045
+ */
1046
+ socialProviders?: SocialProviders;
1047
+ /**
1048
+ * List of Better Auth plugins
1049
+ */
1050
+ plugins?: [] | BetterAuthPlugin[];
1051
+ /**
1052
+ * User configuration
1053
+ */
1054
+ user?: {
1055
+ /**
1056
+ * The model name for the user. Defaults to "user".
1057
+ */
1058
+ modelName?: string;
1059
+ /**
1060
+ * Map fields
1061
+ *
1062
+ * @example
1063
+ * ```ts
1064
+ * {
1065
+ * userId: "user_id"
1066
+ * }
1067
+ * ```
1068
+ */
1069
+ fields?: Partial<Record<keyof OmitId<User>, string>>;
1070
+ /**
1071
+ * Additional fields for the user
1072
+ */
1073
+ additionalFields?: {
1074
+ [key: string]: DBFieldAttribute;
1075
+ };
1076
+ /**
1077
+ * Changing email configuration
1078
+ */
1079
+ changeEmail?: {
1080
+ /**
1081
+ * Enable changing email
1082
+ * @default false
1083
+ */
1084
+ enabled: boolean;
1085
+ /**
1086
+ * Send a verification email when the user changes their email.
1087
+ * @param data the data object
1088
+ * @param request the request object
1089
+ */
1090
+ sendChangeEmailVerification?: (data: {
1091
+ user: User;
1092
+ newEmail: string;
1093
+ url: string;
1094
+ token: string;
1095
+ }, request?: Request) => Promise<void>;
1096
+ };
1097
+ /**
1098
+ * User deletion configuration
1099
+ */
1100
+ deleteUser?: {
1101
+ /**
1102
+ * Enable user deletion
1103
+ */
1104
+ enabled?: boolean;
1105
+ /**
1106
+ * Send a verification email when the user deletes their account.
1107
+ *
1108
+ * if this is not set, the user will be deleted immediately.
1109
+ * @param data the data object
1110
+ * @param request the request object
1111
+ */
1112
+ sendDeleteAccountVerification?: (data: {
1113
+ user: User;
1114
+ url: string;
1115
+ token: string;
1116
+ }, request?: Request) => Promise<void>;
1117
+ /**
1118
+ * A function that is called before a user is deleted.
1119
+ *
1120
+ * to interrupt with error you can throw `APIError`
1121
+ */
1122
+ beforeDelete?: (user: User, request?: Request) => Promise<void>;
1123
+ /**
1124
+ * A function that is called after a user is deleted.
1125
+ *
1126
+ * This is useful for cleaning up user data
1127
+ */
1128
+ afterDelete?: (user: User, request?: Request) => Promise<void>;
1129
+ /**
1130
+ * The expiration time for the delete token.
1131
+ *
1132
+ * @default 1 day (60 * 60 * 24) in seconds
1133
+ */
1134
+ deleteTokenExpiresIn?: number;
1135
+ };
1136
+ };
1137
+ session?: {
1138
+ /**
1139
+ * The model name for the session.
1140
+ *
1141
+ * @default "session"
1142
+ */
1143
+ modelName?: string;
1144
+ /**
1145
+ * Map fields
1146
+ *
1147
+ * @example
1148
+ * ```ts
1149
+ * {
1150
+ * userId: "user_id"
1151
+ * }
1152
+ */
1153
+ fields?: Partial<Record<keyof OmitId<Session>, string>>;
1154
+ /**
1155
+ * Expiration time for the session token. The value
1156
+ * should be in seconds.
1157
+ * @default 7 days (60 * 60 * 24 * 7)
1158
+ */
1159
+ expiresIn?: number;
1160
+ /**
1161
+ * How often the session should be refreshed. The value
1162
+ * should be in seconds.
1163
+ * If set 0 the session will be refreshed every time it is used.
1164
+ * @default 1 day (60 * 60 * 24)
1165
+ */
1166
+ updateAge?: number;
1167
+ /**
1168
+ * Disable session refresh so that the session is not updated
1169
+ * regardless of the `updateAge` option.
1170
+ *
1171
+ * @default false
1172
+ */
1173
+ disableSessionRefresh?: boolean;
1174
+ /**
1175
+ * Additional fields for the session
1176
+ */
1177
+ additionalFields?: {
1178
+ [key: string]: DBFieldAttribute;
1179
+ };
1180
+ /**
1181
+ * By default if secondary storage is provided
1182
+ * the session is stored in the secondary storage.
1183
+ *
1184
+ * Set this to true to store the session in the database
1185
+ * as well.
1186
+ *
1187
+ * Reads are always done from the secondary storage.
1188
+ *
1189
+ * @default false
1190
+ */
1191
+ storeSessionInDatabase?: boolean;
1192
+ /**
1193
+ * By default, sessions are deleted from the database when secondary storage
1194
+ * is provided when session is revoked.
1195
+ *
1196
+ * Set this to true to preserve session records in the database,
1197
+ * even if they are deleted from the secondary storage.
1198
+ *
1199
+ * @default false
1200
+ */
1201
+ preserveSessionInDatabase?: boolean;
1202
+ /**
1203
+ * Enable caching session in cookie
1204
+ */
1205
+ cookieCache?: {
1206
+ /**
1207
+ * max age of the cookie
1208
+ * @default 5 minutes (5 * 60)
1209
+ */
1210
+ maxAge?: number;
1211
+ /**
1212
+ * Enable caching session in cookie
1213
+ * @default false
1214
+ */
1215
+ enabled?: boolean;
1216
+ };
1217
+ /**
1218
+ * The age of the session to consider it fresh.
1219
+ *
1220
+ * This is used to check if the session is fresh
1221
+ * for sensitive operations. (e.g. deleting an account)
1222
+ *
1223
+ * If the session is not fresh, the user should be prompted
1224
+ * to sign in again.
1225
+ *
1226
+ * If set to 0, the session will be considered fresh every time. (⚠︎ not recommended)
1227
+ *
1228
+ * @default 1 day (60 * 60 * 24)
1229
+ */
1230
+ freshAge?: number;
1231
+ };
1232
+ account?: {
1233
+ /**
1234
+ * The model name for the account. Defaults to "account".
1235
+ */
1236
+ modelName?: string;
1237
+ /**
1238
+ * Map fields
1239
+ */
1240
+ fields?: Partial<Record<keyof OmitId<Account>, string>>;
1241
+ /**
1242
+ * Additional fields for the account
1243
+ */
1244
+ additionalFields?: {
1245
+ [key: string]: DBFieldAttribute;
1246
+ };
1247
+ /**
1248
+ * When enabled (true), the user account data (accessToken, idToken, refreshToken, etc.)
1249
+ * will be updated on sign in with the latest data from the provider.
1250
+ *
1251
+ * @default true
1252
+ */
1253
+ updateAccountOnSignIn?: boolean;
1254
+ /**
1255
+ * Configuration for account linking.
1256
+ */
1257
+ accountLinking?: {
1258
+ /**
1259
+ * Enable account linking
1260
+ *
1261
+ * @default true
1262
+ */
1263
+ enabled?: boolean;
1264
+ /**
1265
+ * List of trusted providers
1266
+ */
1267
+ trustedProviders?: Array<LiteralUnion<SocialProviderList[number] | "email-password", string>>;
1268
+ /**
1269
+ * If enabled (true), this will allow users to manually linking accounts with different email addresses than the main user.
1270
+ *
1271
+ * @default false
1272
+ *
1273
+ * ⚠️ Warning: enabling this might lead to account takeovers, so proceed with caution.
1274
+ */
1275
+ allowDifferentEmails?: boolean;
1276
+ /**
1277
+ * If enabled (true), this will allow users to unlink all accounts.
1278
+ *
1279
+ * @default false
1280
+ */
1281
+ allowUnlinkingAll?: boolean;
1282
+ /**
1283
+ * If enabled (true), this will update the user information based on the newly linked account
1284
+ *
1285
+ * @default false
1286
+ */
1287
+ updateUserInfoOnLink?: boolean;
1288
+ };
1289
+ /**
1290
+ * Encrypt OAuth tokens
1291
+ *
1292
+ * By default, OAuth tokens (access tokens, refresh tokens, ID tokens) are stored in plain text in the database.
1293
+ * This poses a security risk if your database is compromised, as attackers could gain access to user accounts
1294
+ * on external services.
1295
+ *
1296
+ * When enabled, tokens are encrypted using AES-256-GCM before storage, providing protection against:
1297
+ * - Database breaches and unauthorized access to raw token data
1298
+ * - Internal threats from database administrators or compromised credentials
1299
+ * - Token exposure in database backups and logs
1300
+ * @default false
1301
+ */
1302
+ encryptOAuthTokens?: boolean;
1303
+ };
1304
+ /**
1305
+ * Verification configuration
1306
+ */
1307
+ verification?: {
1308
+ /**
1309
+ * Change the modelName of the verification table
1310
+ */
1311
+ modelName?: string;
1312
+ /**
1313
+ * Map verification fields
1314
+ */
1315
+ fields?: Partial<Record<keyof OmitId<Verification>, string>>;
1316
+ /**
1317
+ * disable cleaning up expired values when a verification value is
1318
+ * fetched
1319
+ */
1320
+ disableCleanup?: boolean;
1321
+ };
1322
+ /**
1323
+ * List of trusted origins.
1324
+ */
1325
+ trustedOrigins?: string[] | ((request: Request) => string[] | Promise<string[]>);
1326
+ /**
1327
+ * Rate limiting configuration
1328
+ */
1329
+ rateLimit?: BetterAuthRateLimitOptions;
1330
+ /**
1331
+ * Advanced options
1332
+ */
1333
+ advanced?: BetterAuthAdvancedOptions & {
1334
+ /**
1335
+ * @deprecated Please use `database.generateId` instead.
1336
+ */
1337
+ generateId?: never;
1338
+ };
1339
+ logger?: Logger;
1340
+ /**
1341
+ * allows you to define custom hooks that can be
1342
+ * executed during lifecycle of core database
1343
+ * operations.
1344
+ */
1345
+ databaseHooks?: {
1346
+ /**
1347
+ * User hooks
1348
+ */
1349
+ user?: {
1350
+ create?: {
1351
+ /**
1352
+ * Hook that is called before a user is created.
1353
+ * if the hook returns false, the user will not be created.
1354
+ * If the hook returns an object, it'll be used instead of the original data
1355
+ */
1356
+ before?: (user: User & Record<string, unknown>, context?: GenericEndpointContext) => Promise<boolean | void | {
1357
+ data: Optional<User> & Record<string, any>;
1358
+ }>;
1359
+ /**
1360
+ * Hook that is called after a user is created.
1361
+ */
1362
+ after?: (user: User & Record<string, unknown>, context?: GenericEndpointContext) => Promise<void>;
1363
+ };
1364
+ update?: {
1365
+ /**
1366
+ * Hook that is called before a user is updated.
1367
+ * if the hook returns false, the user will not be updated.
1368
+ * If the hook returns an object, it'll be used instead of the original data
1369
+ */
1370
+ before?: (user: Partial<User> & Record<string, unknown>, context?: GenericEndpointContext) => Promise<boolean | void | {
1371
+ data: Optional<User & Record<string, any>>;
1372
+ }>;
1373
+ /**
1374
+ * Hook that is called after a user is updated.
1375
+ */
1376
+ after?: (user: User & Record<string, unknown>, context?: GenericEndpointContext) => Promise<void>;
1377
+ };
1378
+ delete?: {
1379
+ /**
1380
+ * Hook that is called before a user is deleted.
1381
+ * if the hook returns false, the user will not be deleted.
1382
+ */
1383
+ before?: (user: User & Record<string, unknown>, context?: GenericEndpointContext) => Promise<boolean | void>;
1384
+ /**
1385
+ * Hook that is called after a user is deleted.
1386
+ */
1387
+ after?: (user: User & Record<string, unknown>, context?: GenericEndpointContext) => Promise<void>;
1388
+ };
1389
+ };
1390
+ /**
1391
+ * Session Hook
1392
+ */
1393
+ session?: {
1394
+ create?: {
1395
+ /**
1396
+ * Hook that is called before a session is created.
1397
+ * if the hook returns false, the session will not be created.
1398
+ * If the hook returns an object, it'll be used instead of the original data
1399
+ */
1400
+ before?: (session: Session & Record<string, unknown>, context?: GenericEndpointContext) => Promise<boolean | void | {
1401
+ data: Optional<Session> & Record<string, any>;
1402
+ }>;
1403
+ /**
1404
+ * Hook that is called after a session is created.
1405
+ */
1406
+ after?: (session: Session & Record<string, unknown>, context?: GenericEndpointContext) => Promise<void>;
1407
+ };
1408
+ /**
1409
+ * Update hook
1410
+ */
1411
+ update?: {
1412
+ /**
1413
+ * Hook that is called before a user is updated.
1414
+ * if the hook returns false, the session will not be updated.
1415
+ * If the hook returns an object, it'll be used instead of the original data
1416
+ */
1417
+ before?: (session: Partial<Session> & Record<string, unknown>, context?: GenericEndpointContext) => Promise<boolean | void | {
1418
+ data: Optional<Session & Record<string, any>>;
1419
+ }>;
1420
+ /**
1421
+ * Hook that is called after a session is updated.
1422
+ */
1423
+ after?: (session: Session & Record<string, unknown>, context?: GenericEndpointContext) => Promise<void>;
1424
+ };
1425
+ delete?: {
1426
+ /**
1427
+ * Hook that is called before a session is deleted.
1428
+ * if the hook returns false, the session will not be deleted.
1429
+ */
1430
+ before?: (session: Session & Record<string, unknown>, context?: GenericEndpointContext) => Promise<boolean | void>;
1431
+ /**
1432
+ * Hook that is called after a session is deleted.
1433
+ */
1434
+ after?: (session: Session & Record<string, unknown>, context?: GenericEndpointContext) => Promise<void>;
1435
+ };
1436
+ };
1437
+ /**
1438
+ * Account Hook
1439
+ */
1440
+ account?: {
1441
+ create?: {
1442
+ /**
1443
+ * Hook that is called before a account is created.
1444
+ * If the hook returns false, the account will not be created.
1445
+ * If the hook returns an object, it'll be used instead of the original data
1446
+ */
1447
+ before?: (account: Account, context?: GenericEndpointContext) => Promise<boolean | void | {
1448
+ data: Optional<Account> & Record<string, any>;
1449
+ }>;
1450
+ /**
1451
+ * Hook that is called after a account is created.
1452
+ */
1453
+ after?: (account: Account, context?: GenericEndpointContext) => Promise<void>;
1454
+ };
1455
+ /**
1456
+ * Update hook
1457
+ */
1458
+ update?: {
1459
+ /**
1460
+ * Hook that is called before a account is update.
1461
+ * If the hook returns false, the user will not be updated.
1462
+ * If the hook returns an object, it'll be used instead of the original data
1463
+ */
1464
+ before?: (account: Partial<Account> & Record<string, unknown>, context?: GenericEndpointContext) => Promise<boolean | void | {
1465
+ data: Optional<Account & Record<string, any>>;
1466
+ }>;
1467
+ /**
1468
+ * Hook that is called after a account is updated.
1469
+ */
1470
+ after?: (account: Account & Record<string, unknown>, context?: GenericEndpointContext) => Promise<void>;
1471
+ };
1472
+ delete?: {
1473
+ /**
1474
+ * Hook that is called before an account is deleted.
1475
+ * if the hook returns false, the account will not be deleted.
1476
+ */
1477
+ before?: (account: Account & Record<string, unknown>, context?: GenericEndpointContext) => Promise<boolean | void>;
1478
+ /**
1479
+ * Hook that is called after an account is deleted.
1480
+ */
1481
+ after?: (account: Account & Record<string, unknown>, context?: GenericEndpointContext) => Promise<void>;
1482
+ };
1483
+ };
1484
+ /**
1485
+ * Verification Hook
1486
+ */
1487
+ verification?: {
1488
+ create?: {
1489
+ /**
1490
+ * Hook that is called before a verification is created.
1491
+ * if the hook returns false, the verification will not be created.
1492
+ * If the hook returns an object, it'll be used instead of the original data
1493
+ */
1494
+ before?: (verification: Verification & Record<string, unknown>, context?: GenericEndpointContext) => Promise<boolean | void | {
1495
+ data: Optional<Verification> & Record<string, any>;
1496
+ }>;
1497
+ /**
1498
+ * Hook that is called after a verification is created.
1499
+ */
1500
+ after?: (verification: Verification & Record<string, unknown>, context?: GenericEndpointContext) => Promise<void>;
1501
+ };
1502
+ update?: {
1503
+ /**
1504
+ * Hook that is called before a verification is updated.
1505
+ * if the hook returns false, the verification will not be updated.
1506
+ * If the hook returns an object, it'll be used instead of the original data
1507
+ */
1508
+ before?: (verification: Partial<Verification> & Record<string, unknown>, context?: GenericEndpointContext) => Promise<boolean | void | {
1509
+ data: Optional<Verification & Record<string, any>>;
1510
+ }>;
1511
+ /**
1512
+ * Hook that is called after a verification is updated.
1513
+ */
1514
+ after?: (verification: Verification & Record<string, unknown>, context?: GenericEndpointContext) => Promise<void>;
1515
+ };
1516
+ delete?: {
1517
+ /**
1518
+ * Hook that is called before a verification is deleted.
1519
+ * if the hook returns false, the verification will not be deleted.
1520
+ */
1521
+ before?: (verification: Verification & Record<string, unknown>, context?: GenericEndpointContext) => Promise<boolean | void>;
1522
+ /**
1523
+ * Hook that is called after a verification is deleted.
1524
+ */
1525
+ after?: (verification: Verification & Record<string, unknown>, context?: GenericEndpointContext) => Promise<void>;
1526
+ };
1527
+ };
1528
+ };
1529
+ /**
1530
+ * API error handling
1531
+ */
1532
+ onAPIError?: {
1533
+ /**
1534
+ * Throw an error on API error
1535
+ *
1536
+ * @default false
1537
+ */
1538
+ throw?: boolean;
1539
+ /**
1540
+ * Custom error handler
1541
+ *
1542
+ * @param error
1543
+ * @param ctx - Auth context
1544
+ */
1545
+ onError?: (error: unknown, ctx: AuthContext) => void | Promise<void>;
1546
+ /**
1547
+ * The URL to redirect to on error
1548
+ *
1549
+ * When errorURL is provided, the error will be added to the URL as a query parameter
1550
+ * and the user will be redirected to the errorURL.
1551
+ *
1552
+ * @default - "/api/auth/error"
1553
+ */
1554
+ errorURL?: string;
1555
+ };
1556
+ /**
1557
+ * Hooks
1558
+ */
1559
+ hooks?: {
1560
+ /**
1561
+ * Before a request is processed
1562
+ */
1563
+ before?: AuthMiddleware;
1564
+ /**
1565
+ * After a request is processed
1566
+ */
1567
+ after?: AuthMiddleware;
1568
+ };
1569
+ /**
1570
+ * Disabled paths
1571
+ *
1572
+ * Paths you want to disable.
1573
+ */
1574
+ disabledPaths?: string[];
1575
+ /**
1576
+ * Telemetry configuration
1577
+ */
1578
+ telemetry?: {
1579
+ /**
1580
+ * Enable telemetry collection
1581
+ *
1582
+ * @default false
1583
+ */
1584
+ enabled?: boolean;
1585
+ /**
1586
+ * Enable debug mode
1587
+ *
1588
+ * @default false
1589
+ */
1590
+ debug?: boolean;
1591
+ };
1592
+ };
1593
+ //#endregion
1594
+ //#region src/types/plugin.d.ts
1595
+ type Awaitable<T> = T | Promise<T>;
1596
+ type DeepPartial<T> = T extends Function ? T : T extends object ? { [K in keyof T]?: DeepPartial<T[K]> } : T;
1597
+ type HookEndpointContext = EndpointContext<string, any> & Omit<InputContext<string, any>, "method"> & {
1598
+ context: AuthContext & {
1599
+ returned?: unknown;
1600
+ responseHeaders?: Headers;
1601
+ };
1602
+ headers?: Headers | undefined;
1603
+ };
1604
+ type BetterAuthPlugin = {
1605
+ id: LiteralString;
1606
+ /**
1607
+ * The init function is called when the plugin is initialized.
1608
+ * You can return a new context or modify the existing context.
1609
+ */
1610
+ init?: (ctx: AuthContext) => Awaitable<{
1611
+ context?: DeepPartial<Omit<AuthContext, "options">>;
1612
+ options?: Partial<BetterAuthOptions>;
1613
+ }> | void | Promise<void>;
1614
+ endpoints?: {
1615
+ [key: string]: Endpoint;
1616
+ };
1617
+ middlewares?: {
1618
+ path: string;
1619
+ middleware: Middleware;
1620
+ }[];
1621
+ onRequest?: (request: Request, ctx: AuthContext) => Promise<{
1622
+ response: Response;
1623
+ } | {
1624
+ request: Request;
1625
+ } | void>;
1626
+ onResponse?: (response: Response, ctx: AuthContext) => Promise<{
1627
+ response: Response;
1628
+ } | void>;
1629
+ hooks?: {
1630
+ before?: {
1631
+ matcher: (context: HookEndpointContext) => boolean;
1632
+ handler: AuthMiddleware;
1633
+ }[];
1634
+ after?: {
1635
+ matcher: (context: HookEndpointContext) => boolean;
1636
+ handler: AuthMiddleware;
1637
+ }[];
1638
+ };
1639
+ /**
1640
+ * Schema the plugin needs
1641
+ *
1642
+ * This will also be used to migrate the database. If the fields are dynamic from the plugins
1643
+ * configuration each time the configuration is changed a new migration will be created.
1644
+ *
1645
+ * NOTE: If you want to create migrations manually using
1646
+ * migrations option or any other way you
1647
+ * can disable migration per table basis.
1648
+ *
1649
+ * @example
1650
+ * ```ts
1651
+ * schema: {
1652
+ * user: {
1653
+ * fields: {
1654
+ * email: {
1655
+ * type: "string",
1656
+ * },
1657
+ * emailVerified: {
1658
+ * type: "boolean",
1659
+ * defaultValue: false,
1660
+ * },
1661
+ * },
1662
+ * }
1663
+ * } as AuthPluginSchema
1664
+ * ```
1665
+ */
1666
+ schema?: BetterAuthPluginDBSchema;
1667
+ /**
1668
+ * The migrations of the plugin. If you define schema that will automatically create
1669
+ * migrations for you.
1670
+ *
1671
+ * ⚠️ Only uses this if you dont't want to use the schema option and you disabled migrations for
1672
+ * the tables.
1673
+ */
1674
+ migrations?: Record<string, Migration>;
1675
+ /**
1676
+ * The options of the plugin
1677
+ */
1678
+ options?: Record<string, any> | undefined;
1679
+ /**
1680
+ * types to be inferred
1681
+ */
1682
+ $Infer?: Record<string, any>;
1683
+ /**
1684
+ * The rate limit rules to apply to specific paths.
1685
+ */
1686
+ rateLimit?: {
1687
+ window: number;
1688
+ max: number;
1689
+ pathMatcher: (path: string) => boolean;
1690
+ }[];
1691
+ /**
1692
+ * The error codes returned by the plugin
1693
+ */
1694
+ $ERROR_CODES?: Record<string, string>;
1695
+ };
1696
+ //#endregion
1697
+ //#region src/types/plugin-client.d.ts
1698
+ interface ClientStore {
1699
+ notify: (signal: string) => void;
1700
+ listen: (signal: string, listener: () => void) => void;
1701
+ atoms: Record<string, WritableAtom<any>>;
1702
+ }
1703
+ type ClientAtomListener = {
1704
+ matcher: (path: string) => boolean;
1705
+ signal: "$sessionSignal" | Omit<string, "$sessionSignal">;
1706
+ };
1707
+ interface BetterAuthClientOptions {
1708
+ fetchOptions?: BetterFetchOption;
1709
+ plugins?: BetterAuthClientPlugin[];
1710
+ baseURL?: string;
1711
+ basePath?: string;
1712
+ disableDefaultFetchPlugins?: boolean;
1713
+ $InferAuth?: BetterAuthOptions;
1714
+ }
1715
+ interface BetterAuthClientPlugin {
1716
+ id: LiteralString;
1717
+ /**
1718
+ * only used for type inference. don't pass the
1719
+ * actual plugin
1720
+ */
1721
+ $InferServerPlugin?: BetterAuthPlugin;
1722
+ /**
1723
+ * Custom actions
1724
+ */
1725
+ getActions?: ($fetch: BetterFetch, $store: ClientStore,
1726
+ /**
1727
+ * better-auth client options
1728
+ */
1729
+ options: BetterAuthClientOptions | undefined) => Record<string, any>;
1730
+ /**
1731
+ * State atoms that'll be resolved by each framework
1732
+ * auth store.
1733
+ */
1734
+ getAtoms?: ($fetch: BetterFetch) => Record<string, Atom<any>>;
1735
+ /**
1736
+ * specify path methods for server plugin inferred
1737
+ * endpoints to force a specific method.
1738
+ */
1739
+ pathMethods?: Record<string, "POST" | "GET">;
1740
+ /**
1741
+ * Better fetch plugins
1742
+ */
1743
+ fetchPlugins?: BetterFetchPlugin[];
1744
+ /**
1745
+ * a list of recaller based on a matcher function.
1746
+ * The signal name needs to match a signal in this
1747
+ * plugin or any plugin the user might have added.
1748
+ */
1749
+ atomListeners?: ClientAtomListener[];
1750
+ }
1751
+ //#endregion
1752
+ //#region src/api/index.d.ts
1753
+ declare const optionsMiddleware: <InputCtx extends better_call0.MiddlewareInputContext<better_call0.MiddlewareOptions>>(inputContext: InputCtx) => Promise<AuthContext>;
1754
+ declare const createAuthMiddleware: {
1755
+ <Options extends better_call0.MiddlewareOptions, R>(options: Options, handler: (ctx: better_call0.MiddlewareContext<Options, AuthContext & {
1756
+ returned?: unknown;
1757
+ responseHeaders?: Headers;
1758
+ }>) => Promise<R>): (inputContext: better_call0.MiddlewareInputContext<Options>) => Promise<R>;
1759
+ <Options extends better_call0.MiddlewareOptions, R_1>(handler: (ctx: better_call0.MiddlewareContext<Options, AuthContext & {
1760
+ returned?: unknown;
1761
+ responseHeaders?: Headers;
1762
+ }>) => Promise<R_1>): (inputContext: better_call0.MiddlewareInputContext<Options>) => Promise<R_1>;
1763
+ };
1764
+ declare const createAuthEndpoint: <Path extends string, Opts extends EndpointOptions, R>(path: Path, options: Opts, handler: (ctx: EndpointContext<Path, Opts, AuthContext>) => Promise<R>) => {
1765
+ <AsResponse extends boolean = false, ReturnHeaders extends boolean = false>(...inputCtx: better_call0.HasRequiredKeys<better_call0.InputContext<Path, Opts & {
1766
+ use: any[];
1767
+ }>> extends true ? [better_call0.InferBodyInput<Opts & {
1768
+ use: any[];
1769
+ }, (Opts & {
1770
+ use: any[];
1771
+ })["metadata"] extends {
1772
+ $Infer: {
1773
+ body: infer B;
1774
+ };
1775
+ } ? B : (Opts & {
1776
+ use: any[];
1777
+ })["body"] extends better_call0.StandardSchemaV1<unknown, unknown> ? better_call0.StandardSchemaV1.InferInput<(Opts & {
1778
+ use: any[];
1779
+ })["body"]> : undefined> & better_call0.InferInputMethod<Opts & {
1780
+ use: any[];
1781
+ }, (Opts & {
1782
+ use: any[];
1783
+ })["method"] extends any[] ? (Opts & {
1784
+ use: any[];
1785
+ })["method"][number] : (Opts & {
1786
+ use: any[];
1787
+ })["method"] extends "*" ? better_call0.HTTPMethod : (Opts & {
1788
+ use: any[];
1789
+ })["method"] | undefined> & better_call0.InferQueryInput<Opts & {
1790
+ use: any[];
1791
+ }, (Opts & {
1792
+ use: any[];
1793
+ })["metadata"] extends {
1794
+ $Infer: {
1795
+ query: infer Query;
1796
+ };
1797
+ } ? Query : (Opts & {
1798
+ use: any[];
1799
+ })["query"] extends better_call0.StandardSchemaV1<unknown, unknown> ? better_call0.StandardSchemaV1.InferInput<(Opts & {
1800
+ use: any[];
1801
+ })["query"]> : Record<string, any> | undefined> & better_call0.InferParamInput<Path> & better_call0.InferRequestInput<Opts & {
1802
+ use: any[];
1803
+ }> & better_call0.InferHeadersInput<Opts & {
1804
+ use: any[];
1805
+ }> & {
1806
+ asResponse?: boolean;
1807
+ returnHeaders?: boolean;
1808
+ use?: better_call0.Middleware[];
1809
+ path?: string;
1810
+ } & {
1811
+ asResponse?: AsResponse | undefined;
1812
+ returnHeaders?: ReturnHeaders | undefined;
1813
+ }] : [((better_call0.InferBodyInput<Opts & {
1814
+ use: any[];
1815
+ }, (Opts & {
1816
+ use: any[];
1817
+ })["metadata"] extends {
1818
+ $Infer: {
1819
+ body: infer B;
1820
+ };
1821
+ } ? B : (Opts & {
1822
+ use: any[];
1823
+ })["body"] extends better_call0.StandardSchemaV1<unknown, unknown> ? better_call0.StandardSchemaV1.InferInput<(Opts & {
1824
+ use: any[];
1825
+ })["body"]> : undefined> & better_call0.InferInputMethod<Opts & {
1826
+ use: any[];
1827
+ }, (Opts & {
1828
+ use: any[];
1829
+ })["method"] extends any[] ? (Opts & {
1830
+ use: any[];
1831
+ })["method"][number] : (Opts & {
1832
+ use: any[];
1833
+ })["method"] extends "*" ? better_call0.HTTPMethod : (Opts & {
1834
+ use: any[];
1835
+ })["method"] | undefined> & better_call0.InferQueryInput<Opts & {
1836
+ use: any[];
1837
+ }, (Opts & {
1838
+ use: any[];
1839
+ })["metadata"] extends {
1840
+ $Infer: {
1841
+ query: infer Query;
1842
+ };
1843
+ } ? Query : (Opts & {
1844
+ use: any[];
1845
+ })["query"] extends better_call0.StandardSchemaV1<unknown, unknown> ? better_call0.StandardSchemaV1.InferInput<(Opts & {
1846
+ use: any[];
1847
+ })["query"]> : Record<string, any> | undefined> & better_call0.InferParamInput<Path> & better_call0.InferRequestInput<Opts & {
1848
+ use: any[];
1849
+ }> & better_call0.InferHeadersInput<Opts & {
1850
+ use: any[];
1851
+ }> & {
1852
+ asResponse?: boolean;
1853
+ returnHeaders?: boolean;
1854
+ use?: better_call0.Middleware[];
1855
+ path?: string;
1856
+ } & {
1857
+ asResponse?: AsResponse | undefined;
1858
+ returnHeaders?: ReturnHeaders | undefined;
1859
+ }) | undefined)?]): Promise<[AsResponse] extends [true] ? Response : [ReturnHeaders] extends [true] ? {
1860
+ headers: Headers;
1861
+ response: R;
1862
+ } : R>;
1863
+ options: Opts & {
1864
+ use: any[];
1865
+ };
1866
+ path: Path;
1867
+ };
1868
+ type AuthEndpoint = ReturnType<typeof createAuthEndpoint>;
1869
+ type AuthMiddleware = ReturnType<typeof createAuthMiddleware>;
1870
+ //#endregion
1871
+ export { AuthContext, AuthEndpoint, AuthMiddleware, BetterAuthAdvancedOptions, BetterAuthClientOptions, BetterAuthClientPlugin, BetterAuthCookies, BetterAuthOptions, BetterAuthPlugin, BetterAuthRateLimitOptions, CleanedWhere, ClientAtomListener, ClientStore, CustomAdapter, DBAdapter, DBAdapterDebugLogOption, DBAdapterFactoryConfig, DBAdapterInstance, DBAdapterSchemaCreation, DBTransactionAdapter, GenerateIdFn, GenericEndpointContext, HookEndpointContext, InternalAdapter, Where, createAuthEndpoint, createAuthMiddleware, optionsMiddleware };