@better-auth/core 1.4.0-beta.13 → 1.4.0-beta.15

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