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