@gatwech/core 0.0.10 → 1.0.0-beta.18

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 (130) hide show
  1. package/dist/api/index.d.mts +2 -2
  2. package/dist/context/index.d.mts +2 -2
  3. package/dist/db/adapter/index.d.mts +2 -2
  4. package/dist/db/index.d.mts +2 -2
  5. package/dist/env/index.d.mts +1 -1
  6. package/dist/env/index.mjs +1 -1
  7. package/dist/{env-JMSMESs1.mjs → env-4_Lym7sj.mjs} +7 -7
  8. package/dist/index-65G5U5DB.d.mts +3002 -0
  9. package/dist/{index-DLP-K0uY.d.mts → index-CmdhhvA2.d.mts} +3 -3
  10. package/dist/index.d.mts +3 -3
  11. package/dist/oauth2/index.d.mts +2 -2
  12. package/dist/social-providers/index.d.mts +3 -3
  13. package/dist/social-providers/index.mjs +71 -2412
  14. package/dist/src/api/index.d.ts +119 -0
  15. package/dist/src/async_hooks/index.d.ts +6 -0
  16. package/dist/src/context/endpoint-context.d.ts +14 -0
  17. package/dist/src/context/index.d.ts +3 -0
  18. package/dist/src/context/request-state.d.ts +13 -0
  19. package/dist/src/context/transaction.d.ts +11 -0
  20. package/dist/src/db/adapter/index.d.ts +401 -0
  21. package/{src/db/index.ts → dist/src/db/index.d.ts} +2 -18
  22. package/dist/src/db/plugin.d.ts +10 -0
  23. package/dist/src/db/schema/account.d.ts +22 -0
  24. package/dist/src/db/schema/rate-limit.d.ts +10 -0
  25. package/dist/src/db/schema/session.d.ts +17 -0
  26. package/dist/src/db/schema/shared.d.ts +6 -0
  27. package/dist/src/db/schema/user.d.ts +16 -0
  28. package/{src/db/schema/verification.ts → dist/src/db/schema/verification.d.ts} +8 -8
  29. package/dist/src/db/type.d.ts +159 -0
  30. package/dist/src/env/color-depth.d.ts +1 -0
  31. package/dist/src/env/env-impl.d.ts +29 -0
  32. package/dist/src/env/index.d.ts +3 -0
  33. package/dist/src/env/logger.d.ts +50 -0
  34. package/dist/src/error/codes.d.ts +27 -0
  35. package/dist/src/error/index.d.ts +4 -0
  36. package/dist/src/oauth2/client-credentials-token.d.ts +21 -0
  37. package/dist/src/oauth2/create-authorization-url.d.ts +21 -0
  38. package/dist/src/oauth2/index.d.ts +6 -0
  39. package/dist/src/oauth2/oauth-provider.d.ts +178 -0
  40. package/dist/src/oauth2/refresh-access-token.d.ts +20 -0
  41. package/dist/src/oauth2/utils.d.ts +3 -0
  42. package/dist/src/oauth2/validate-authorization-code.d.ts +28 -0
  43. package/dist/src/social-providers/github.d.ts +89 -0
  44. package/dist/src/social-providers/google.d.ts +82 -0
  45. package/dist/src/social-providers/index.d.ts +93 -0
  46. package/dist/src/types/context.d.ts +177 -0
  47. package/dist/src/types/cookie.d.ts +15 -0
  48. package/dist/src/types/helper.d.ts +9 -0
  49. package/dist/src/types/index.d.ts +7 -0
  50. package/dist/src/types/init-options.d.ts +1140 -0
  51. package/dist/src/types/plugin-client.d.ts +88 -0
  52. package/dist/src/types/plugin.d.ts +120 -0
  53. package/dist/src/utils/error-codes.d.ts +9 -0
  54. package/package.json +11 -5
  55. package/.turbo/turbo-build.log +0 -42
  56. package/dist/index-DjrJweYn.d.mts +0 -7312
  57. package/src/api/index.ts +0 -57
  58. package/src/async_hooks/index.ts +0 -35
  59. package/src/context/endpoint-context.ts +0 -48
  60. package/src/context/index.ts +0 -21
  61. package/src/context/request-state.test.ts +0 -346
  62. package/src/context/request-state.ts +0 -75
  63. package/src/context/transaction.ts +0 -72
  64. package/src/db/adapter/index.ts +0 -466
  65. package/src/db/plugin.ts +0 -11
  66. package/src/db/schema/account.ts +0 -34
  67. package/src/db/schema/rate-limit.ts +0 -21
  68. package/src/db/schema/session.ts +0 -17
  69. package/src/db/schema/shared.ts +0 -7
  70. package/src/db/schema/user.ts +0 -16
  71. package/src/db/type.ts +0 -180
  72. package/src/env/color-depth.ts +0 -172
  73. package/src/env/env-impl.ts +0 -124
  74. package/src/env/index.ts +0 -23
  75. package/src/env/logger.test.ts +0 -33
  76. package/src/env/logger.ts +0 -145
  77. package/src/error/codes.ts +0 -31
  78. package/src/error/index.ts +0 -11
  79. package/src/oauth2/client-credentials-token.ts +0 -102
  80. package/src/oauth2/create-authorization-url.ts +0 -85
  81. package/src/oauth2/index.ts +0 -21
  82. package/src/oauth2/oauth-provider.ts +0 -211
  83. package/src/oauth2/refresh-access-token.ts +0 -124
  84. package/src/oauth2/utils.ts +0 -36
  85. package/src/oauth2/validate-authorization-code.ts +0 -154
  86. package/src/social-providers/apple.ts +0 -213
  87. package/src/social-providers/atlassian.ts +0 -132
  88. package/src/social-providers/cognito.ts +0 -269
  89. package/src/social-providers/discord.ts +0 -169
  90. package/src/social-providers/dropbox.ts +0 -112
  91. package/src/social-providers/facebook.ts +0 -204
  92. package/src/social-providers/figma.ts +0 -115
  93. package/src/social-providers/github.ts +0 -154
  94. package/src/social-providers/gitlab.ts +0 -152
  95. package/src/social-providers/google.ts +0 -171
  96. package/src/social-providers/huggingface.ts +0 -118
  97. package/src/social-providers/index.ts +0 -124
  98. package/src/social-providers/kakao.ts +0 -178
  99. package/src/social-providers/kick.ts +0 -92
  100. package/src/social-providers/line.ts +0 -169
  101. package/src/social-providers/linear.ts +0 -120
  102. package/src/social-providers/linkedin.ts +0 -110
  103. package/src/social-providers/microsoft-entra-id.ts +0 -245
  104. package/src/social-providers/naver.ts +0 -112
  105. package/src/social-providers/notion.ts +0 -108
  106. package/src/social-providers/paybin.ts +0 -122
  107. package/src/social-providers/paypal.ts +0 -263
  108. package/src/social-providers/polar.ts +0 -107
  109. package/src/social-providers/reddit.ts +0 -122
  110. package/src/social-providers/roblox.ts +0 -110
  111. package/src/social-providers/salesforce.ts +0 -159
  112. package/src/social-providers/slack.ts +0 -111
  113. package/src/social-providers/spotify.ts +0 -93
  114. package/src/social-providers/tiktok.ts +0 -210
  115. package/src/social-providers/twitch.ts +0 -111
  116. package/src/social-providers/twitter.ts +0 -198
  117. package/src/social-providers/vk.ts +0 -126
  118. package/src/social-providers/zoom.ts +0 -217
  119. package/src/types/context.ts +0 -269
  120. package/src/types/cookie.ts +0 -7
  121. package/src/types/helper.ts +0 -6
  122. package/src/types/index.ts +0 -21
  123. package/src/types/init-options.ts +0 -1346
  124. package/src/types/plugin-client.ts +0 -100
  125. package/src/types/plugin.ts +0 -158
  126. package/src/utils/error-codes.ts +0 -51
  127. package/tsconfig.json +0 -7
  128. package/tsdown.config.ts +0 -20
  129. /package/{src/index.ts → dist/src/index.d.ts} +0 -0
  130. /package/{src/utils/index.ts → dist/src/utils/index.d.ts} +0 -0
@@ -1,1346 +0,0 @@
1
- import type { Database as BunDatabase } from "bun:sqlite";
2
- import type { DatabaseSync } from "node:sqlite";
3
- import type { CookieOptions } from "better-call";
4
- import type {
5
- Dialect,
6
- Kysely,
7
- MysqlPool,
8
- PostgresPool,
9
- SqliteDatabase,
10
- } from "kysely";
11
- import type { AuthMiddleware } from "../api";
12
- import type {
13
- Account,
14
- DBFieldAttribute,
15
- DBPreservedModels,
16
- RateLimit,
17
- SecondaryStorage,
18
- Session,
19
- User,
20
- Verification,
21
- } from "../db";
22
- import type { DBAdapterDebugLogOption, DBAdapterInstance } from "../db/adapter";
23
- import type { Logger } from "../env";
24
- import type { SocialProviderList, SocialProviders } from "../social-providers";
25
- import type { AuthContext, GenericEndpointContext } from "./context";
26
- import type { LiteralUnion } from "./helper";
27
- import type { PayvoAuthPlugin } from "./plugin";
28
-
29
- type KyselyDatabaseType = "postgres" | "mysql" | "sqlite" | "mssql";
30
- type OmitId<T extends { id: unknown }> = Omit<T, "id">;
31
- type Optional<T> = {
32
- [P in keyof T]?: T[P] | undefined;
33
- };
34
-
35
- export type GenerateIdFn = (options: {
36
- model: LiteralUnion<DBPreservedModels, string>;
37
- size?: number | undefined;
38
- }) => string | false;
39
-
40
- export type PayvoAuthRateLimitOptions = {
41
- /**
42
- * By default, rate limiting is only
43
- * enabled on production.
44
- */
45
- enabled?: boolean | undefined;
46
- /**
47
- * Default window to use for rate limiting. The value
48
- * should be in seconds.
49
- *
50
- * @default 10 seconds
51
- */
52
- window?: number | undefined;
53
- /**
54
- * The default maximum number of requests allowed within the window.
55
- *
56
- * @default 100 requests
57
- */
58
- max?: number | undefined;
59
- /**
60
- * Custom rate limit rules to apply to
61
- * specific paths.
62
- */
63
- customRules?:
64
- | {
65
- [key: string]:
66
- | {
67
- /**
68
- * The window to use for the custom rule.
69
- */
70
- window: number;
71
- /**
72
- * The maximum number of requests allowed within the window.
73
- */
74
- max: number;
75
- }
76
- | false
77
- | ((request: Request) =>
78
- | { window: number; max: number }
79
- | false
80
- | Promise<
81
- | {
82
- window: number;
83
- max: number;
84
- }
85
- | false
86
- >);
87
- }
88
- | undefined;
89
- /**
90
- * Storage configuration
91
- *
92
- * By default, rate limiting is stored in memory. If you passed a
93
- * secondary storage, rate limiting will be stored in the secondary
94
- * storage.
95
- *
96
- * @default "memory"
97
- */
98
- storage?: ("memory" | "database" | "secondary-storage") | undefined;
99
- /**
100
- * If database is used as storage, the name of the table to
101
- * use for rate limiting.
102
- *
103
- * @default "rateLimit"
104
- */
105
- modelName?: string | undefined;
106
- /**
107
- * Custom field names for the rate limit table
108
- */
109
- fields?: Record<keyof RateLimit, string> | undefined;
110
- /**
111
- * custom storage configuration.
112
- *
113
- * NOTE: If custom storage is used storage
114
- * is ignored
115
- */
116
- customStorage?: {
117
- get: (key: string) => Promise<RateLimit | undefined>;
118
- set: (key: string, value: RateLimit) => Promise<void>;
119
- };
120
- };
121
-
122
- export type PayvoAuthAdvancedOptions = {
123
- /**
124
- * Ip address configuration
125
- */
126
- ipAddress?:
127
- | {
128
- /**
129
- * List of headers to use for ip address
130
- *
131
- * Ip address is used for rate limiting and session tracking
132
- *
133
- * @example ["x-client-ip", "x-forwarded-for", "cf-connecting-ip"]
134
- *
135
- * @default
136
- * @link https://github.com/payvo-auth/payvo-auth/blob/main/packages/payvo-auth/src/utils/get-request-ip.ts#L8
137
- */
138
- ipAddressHeaders?: string[];
139
- /**
140
- * Disable ip tracking
141
- *
142
- * ⚠︎ This is a security risk and it may expose your application to abuse
143
- */
144
- disableIpTracking?: boolean;
145
- }
146
- | undefined;
147
- /**
148
- * Use secure cookies
149
- *
150
- * @default false
151
- */
152
- useSecureCookies?: boolean | undefined;
153
- /**
154
- * Disable trusted origins check
155
- *
156
- * ⚠︎ This is a security risk and it may expose your application to
157
- * CSRF attacks
158
- */
159
- disableCSRFCheck?: boolean | undefined;
160
- /**
161
- * Disable origin check
162
- *
163
- * ⚠︎ This may allow requests from any origin to be processed by
164
- * Better Auth. And could lead to security vulnerabilities.
165
- */
166
- disableOriginCheck?: boolean | undefined;
167
- /**
168
- * Configure cookies to be cross subdomains
169
- */
170
- crossSubDomainCookies?:
171
- | {
172
- /**
173
- * Enable cross subdomain cookies
174
- */
175
- enabled: boolean;
176
- /**
177
- * Additional cookies to be shared across subdomains
178
- */
179
- additionalCookies?: string[];
180
- /**
181
- * The domain to use for the cookies
182
- *
183
- * By default, the domain will be the root
184
- * domain from the base URL.
185
- */
186
- domain?: string;
187
- }
188
- | undefined;
189
- /*
190
- * Allows you to change default cookie names and attributes
191
- *
192
- * default cookie names:
193
- * - "session_token"
194
- * - "session_data"
195
- * - "dont_remember"
196
- *
197
- * plugins can also add additional cookies
198
- */
199
- cookies?:
200
- | {
201
- [key: string]: {
202
- name?: string;
203
- attributes?: CookieOptions;
204
- };
205
- }
206
- | undefined;
207
- defaultCookieAttributes?: CookieOptions | undefined;
208
- /**
209
- * Prefix for cookies. If a cookie name is provided
210
- * in cookies config, this will be overridden.
211
- *
212
- * @default
213
- * ```txt
214
- * "appName" -> which defaults to "gatwech"
215
- * ```
216
- */
217
- cookiePrefix?: string | undefined;
218
- /**
219
- * Database configuration.
220
- */
221
- database?:
222
- | {
223
- /**
224
- * The default number of records to return from the database
225
- * when using the `findMany` adapter method.
226
- *
227
- * @default 100
228
- */
229
- defaultFindManyLimit?: number;
230
- /**
231
- * If your database auto increments number ids, set this to `true`.
232
- *
233
- * 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.
234
- *
235
- * @default false
236
- *
237
- * @deprecated Please use `generateId` instead. This will be removed in future
238
- * releases.
239
- */
240
- useNumberId?: boolean;
241
- /**
242
- * Custom generateId function.
243
- *
244
- * If not provided, random ids will be generated.
245
- * If set to false, the database's auto generated id
246
- * will be used.
247
- *
248
- * If set to "serial", the database's auto generated
249
- * id will be used.
250
- *
251
- * If set to "uuid", we generate a random UUID for
252
- * the id. If postgres, we use the `gen_random_uuid()
253
- * ` function. If mysql or mssql, we use the `uuid()`
254
- * function.
255
- */
256
- generateId?: GenerateIdFn | false | "serial" | "uuid";
257
- }
258
- | undefined;
259
- /**
260
- * OAuth configuration
261
- */
262
- oauthConfig?:
263
- | {
264
- /**
265
- * Skip state cookie check
266
- *
267
- * ⚠︎ this has security implications and should only be enabled if you know what you are doing.
268
- * @default false
269
- */
270
- skipStateCookieCheck?: boolean;
271
- /**
272
- * Strategy for storing OAuth state
273
- *
274
- * - "cookie": Store state in an encrypted cookie (stateless)
275
- * - "database": Store state in the database
276
- *
277
- * @default "cookie"
278
- */
279
- storeStateStrategy?: "database" | "cookie";
280
- }
281
- | undefined;
282
- };
283
-
284
- export type PayvoAuthOptions = {
285
- /**
286
- * The name of the application
287
- *
288
- * process.env.APP_NAME
289
- *
290
- * @default "Better Auth"
291
- */
292
- appName?: string | undefined;
293
- /**
294
- * Base URL for the Better Auth. This is typically the
295
- * root URL where your application server is hosted.
296
- * If not explicitly set,
297
- * the system will check the following environment variable:
298
- *
299
- * process.env.PAYVO_AUTH_URL
300
- */
301
- baseURL?: string | undefined;
302
- /**
303
- * Base path for the Better Auth. This is typically
304
- * the path where the
305
- * Better Auth routes are mounted.
306
- *
307
- * @default "/api/v1/auth"
308
- */
309
- basePath?: string | undefined;
310
- /**
311
- * The secret to use for encryption,
312
- * signing and hashing.
313
- *
314
- * By default Better Auth will look for
315
- * the following environment variables:
316
- * process.env.PAYVO_AUTH_SECRET,
317
- * process.env.AUTH_SECRET
318
- * If none of these environment
319
- * variables are set,
320
- * it will default to
321
- * "payvo-auth-secret-123456789".
322
- *
323
- * on production if it's not set
324
- * it will throw an error.
325
- *
326
- * you can generate a good secret
327
- * using the following command:
328
- * @example
329
- * ```bash
330
- * openssl rand -base64 32
331
- * ```
332
- */
333
- secret?: string | undefined;
334
- /**
335
- * Database configuration
336
- */
337
- database?:
338
- | (
339
- | PostgresPool
340
- | MysqlPool
341
- | SqliteDatabase
342
- | Dialect
343
- | DBAdapterInstance
344
- | BunDatabase
345
- | DatabaseSync
346
- | {
347
- dialect: Dialect;
348
- type: KyselyDatabaseType;
349
- /**
350
- * casing for table names
351
- *
352
- * @default "camel"
353
- */
354
- casing?: "snake" | "camel";
355
- /**
356
- * Enable debug logs for the adapter
357
- *
358
- * @default false
359
- */
360
- debugLogs?: DBAdapterDebugLogOption;
361
- /**
362
- * Whether to execute multiple operations in a transaction.
363
- * If the database doesn't support transactions,
364
- * set this to `false` and operations will be executed sequentially.
365
- * @default true
366
- */
367
- transaction?: boolean;
368
- }
369
- | {
370
- /**
371
- * Kysely instance
372
- */
373
- db: Kysely<any>;
374
- /**
375
- * Database type between postgres, mysql and sqlite
376
- */
377
- type: KyselyDatabaseType;
378
- /**
379
- * casing for table names
380
- *
381
- * @default "camel"
382
- */
383
- casing?: "snake" | "camel";
384
- /**
385
- * Enable debug logs for the adapter
386
- *
387
- * @default false
388
- */
389
- debugLogs?: DBAdapterDebugLogOption;
390
- /**
391
- * Whether to execute multiple operations in a transaction.
392
- * If the database doesn't support transactions,
393
- * set this to `false` and operations will be executed sequentially.
394
- * @default true
395
- */
396
- transaction?: boolean;
397
- }
398
- )
399
- | undefined;
400
- /**
401
- * Secondary storage configuration
402
- *
403
- * This is used to store session and rate limit data.
404
- */
405
- secondaryStorage?: SecondaryStorage | undefined;
406
- /**
407
- * Email verification configuration
408
- */
409
- emailVerification?:
410
- | {
411
- /**
412
- * Send a verification email
413
- * @param data the data object
414
- * @param request the request object
415
- */
416
- sendVerificationEmail?: (
417
- /**
418
- * @param user the user to send the
419
- * verification email to
420
- * @param url the URL to send the verification email to
421
- * it contains the token as well
422
- * @param token the token to send the verification email to
423
- */
424
- data: {
425
- user: User;
426
- url: string;
427
- token: string;
428
- },
429
- /**
430
- * The request object
431
- */
432
- request?: Request
433
- ) => Promise<void>;
434
- /**
435
- * Send a verification email automatically
436
- * after sign up
437
- *
438
- * @default false
439
- */
440
- sendOnSignUp?: boolean;
441
- /**
442
- * Send a verification email automatically
443
- * on sign in when the user's email is not verified
444
- *
445
- * @default false
446
- */
447
- sendOnSignIn?: boolean;
448
- /**
449
- * Auto signin the user after they verify their email
450
- */
451
- autoSignInAfterVerification?: boolean;
452
- /**
453
- * Number of seconds the verification token is
454
- * valid for.
455
- * @default 3600 seconds (1 hour)
456
- */
457
- expiresIn?: number;
458
- /**
459
- * A function that is called when a user verifies their email
460
- * @param user the user that verified their email
461
- * @param request the request object
462
- */
463
- onEmailVerification?: (user: User, request?: Request) => Promise<void>;
464
- /**
465
- * A function that is called when a user's email is updated to verified
466
- * @param user the user that verified their email
467
- * @param request the request object
468
- */
469
- afterEmailVerification?: (
470
- user: User,
471
- request?: Request
472
- ) => Promise<void>;
473
- }
474
- | undefined;
475
- /**
476
- * Email and password authentication
477
- */
478
- emailAndPassword?:
479
- | {
480
- /**
481
- * Enable email and password authentication
482
- *
483
- * @default false
484
- */
485
- enabled: boolean;
486
- /**
487
- * Disable email and password sign up
488
- *
489
- * @default false
490
- */
491
- disableSignUp?: boolean;
492
- /**
493
- * Require email verification before a session
494
- * can be created for the user.
495
- *
496
- * if the user is not verified, the user will not be able to sign in
497
- * and on sign in attempts, the user will be prompted to verify their email.
498
- */
499
- requireEmailVerification?: boolean;
500
- /**
501
- * The maximum length of the password.
502
- *
503
- * @default 128
504
- */
505
- maxPasswordLength?: number;
506
- /**
507
- * The minimum length of the password.
508
- *
509
- * @default 8
510
- */
511
- minPasswordLength?: number;
512
- /**
513
- * send reset password
514
- */
515
- sendResetPassword?: (
516
- /**
517
- * @param user the user to send the
518
- * reset password email to
519
- * @param url the URL to send the reset password email to
520
- * @param token the token to send to the user (could be used instead of sending the url
521
- * if you need to redirect the user to custom route)
522
- */
523
- data: { user: User; url: string; token: string },
524
- /**
525
- * The request object
526
- */
527
- request?: Request
528
- ) => Promise<void>;
529
- /**
530
- * Number of seconds the reset password token is
531
- * valid for.
532
- * @default 1 hour (60 * 60)
533
- */
534
- resetPasswordTokenExpiresIn?: number;
535
- /**
536
- * A callback function that is triggered
537
- * when a user's password is changed successfully.
538
- */
539
- onPasswordReset?: (
540
- data: { user: User },
541
- request?: Request
542
- ) => Promise<void>;
543
- /**
544
- * Password hashing and verification
545
- *
546
- * By default Scrypt is used for password hashing and
547
- * verification. You can provide your own hashing and
548
- * verification function. if you want to use a
549
- * different algorithm.
550
- */
551
- password?: {
552
- hash?: (password: string) => Promise<string>;
553
- verify?: (data: {
554
- hash: string;
555
- password: string;
556
- }) => Promise<boolean>;
557
- };
558
- /**
559
- * Automatically sign in the user after sign up
560
- *
561
- * @default true
562
- */
563
- autoSignIn?: boolean;
564
- /**
565
- * Whether to revoke all other sessions when resetting password
566
- * @default false
567
- */
568
- revokeSessionsOnPasswordReset?: boolean;
569
- }
570
- | undefined;
571
- /**
572
- * list of social providers
573
- */
574
- socialProviders?: SocialProviders | undefined;
575
- /**
576
- * List of Better Auth plugins
577
- */
578
- plugins?: ([] | PayvoAuthPlugin[]) | undefined;
579
- /**
580
- * User configuration
581
- */
582
- user?:
583
- | {
584
- /**
585
- * The model name for the user. Defaults to "user".
586
- */
587
- modelName?: string;
588
- /**
589
- * Map fields
590
- *
591
- * @example
592
- * ```ts
593
- * {
594
- * userId: "user_id"
595
- * }
596
- * ```
597
- */
598
- fields?: Partial<Record<keyof OmitId<User>, string>>;
599
- /**
600
- * Additional fields for the user
601
- */
602
- additionalFields?: {
603
- [key: string]: DBFieldAttribute;
604
- };
605
- /**
606
- * Changing email configuration
607
- */
608
- changeEmail?: {
609
- /**
610
- * Enable changing email
611
- * @default false
612
- */
613
- enabled: boolean;
614
- /**
615
- * Send a verification email when the user changes their email.
616
- * @param data the data object
617
- * @param request the request object
618
- */
619
- sendChangeEmailVerification?: (
620
- data: {
621
- user: User;
622
- newEmail: string;
623
- url: string;
624
- token: string;
625
- },
626
- request?: Request
627
- ) => Promise<void>;
628
- };
629
- /**
630
- * User deletion configuration
631
- */
632
- deleteUser?: {
633
- /**
634
- * Enable user deletion
635
- */
636
- enabled?: boolean;
637
- /**
638
- * Send a verification email when the user deletes their account.
639
- *
640
- * if this is not set, the user will be deleted immediately.
641
- * @param data the data object
642
- * @param request the request object
643
- */
644
- sendDeleteAccountVerification?: (
645
- data: {
646
- user: User;
647
- url: string;
648
- token: string;
649
- },
650
- request?: Request
651
- ) => Promise<void>;
652
- /**
653
- * A function that is called before a user is deleted.
654
- *
655
- * to interrupt with error you can throw `APIError`
656
- */
657
- beforeDelete?: (user: User, request?: Request) => Promise<void>;
658
- /**
659
- * A function that is called after a user is deleted.
660
- *
661
- * This is useful for cleaning up user data
662
- */
663
- afterDelete?: (user: User, request?: Request) => Promise<void>;
664
- /**
665
- * The expiration time for the delete token.
666
- *
667
- * @default 1 day (60 * 60 * 24) in seconds
668
- */
669
- deleteTokenExpiresIn?: number;
670
- };
671
- }
672
- | undefined;
673
- session?:
674
- | {
675
- /**
676
- * The model name for the session.
677
- *
678
- * @default "session"
679
- */
680
- modelName?: string;
681
- /**
682
- * Map fields
683
- *
684
- * @example
685
- * ```ts
686
- * {
687
- * userId: "user_id"
688
- * }
689
- */
690
- fields?: Partial<Record<keyof OmitId<Session>, string>>;
691
- /**
692
- * Expiration time for the session token. The value
693
- * should be in seconds.
694
- * @default 7 days (60 * 60 * 24 * 7)
695
- */
696
- expiresIn?: number;
697
- /**
698
- * How often the session should be refreshed. The value
699
- * should be in seconds.
700
- * If set 0 the session will be refreshed every time it is used.
701
- * @default 1 day (60 * 60 * 24)
702
- */
703
- updateAge?: number;
704
- /**
705
- * Disable session refresh so that the session is not updated
706
- * regardless of the `updateAge` option.
707
- *
708
- * @default false
709
- */
710
- disableSessionRefresh?: boolean;
711
- /**
712
- * Additional fields for the session
713
- */
714
- additionalFields?: {
715
- [key: string]: DBFieldAttribute;
716
- };
717
- /**
718
- * By default if secondary storage is provided
719
- * the session is stored in the secondary storage.
720
- *
721
- * Set this to true to store the session in the database
722
- * as well.
723
- *
724
- * Reads are always done from the secondary storage.
725
- *
726
- * @default false
727
- */
728
- storeSessionInDatabase?: boolean;
729
- /**
730
- * By default, sessions are deleted from the database when secondary storage
731
- * is provided when session is revoked.
732
- *
733
- * Set this to true to preserve session records in the database,
734
- * even if they are deleted from the secondary storage.
735
- *
736
- * @default false
737
- */
738
- preserveSessionInDatabase?: boolean;
739
- /**
740
- * Enable caching session in cookie
741
- */
742
- cookieCache?: {
743
- /**
744
- * max age of the cookie
745
- * @default 5 minutes (5 * 60)
746
- */
747
- maxAge?: number;
748
- /**
749
- * Enable caching session in cookie
750
- * @default false
751
- */
752
- enabled?: boolean;
753
- /**
754
- * Strategy for encoding/decoding cookie cache
755
- *
756
- * - "compact": Uses base64url encoding with HMAC-SHA256 signature (compact format, no JWT spec overhead)
757
- * - "jwt": Uses JWT with HMAC signature (no encryption, follows JWT spec)
758
- * - "jwe": Uses JWE (JSON Web Encryption) with A256CBC-HS512 and HKDF key derivation for secure encrypted tokens
759
- *
760
- * @default "compact"
761
- */
762
- strategy?: "compact" | "jwt" | "jwe";
763
- /**
764
- * Controls stateless cookie cache refresh behavior.
765
- *
766
- * When enabled, the cookie cache will be automatically refreshed before expiry
767
- * WITHOUT querying the database. This is essential for fully stateless or DB-less scenarios.
768
- *
769
- * - `false`: Disable automatic refresh. Cache is only invalidated when it reaches maxAge expiry.
770
- * - `true`: Enable automatic refresh with default settings (refreshes when 80% of maxAge is reached).
771
- * - `object`: Custom refresh configuration with either `updateAge` or `shouldRefresh` function
772
- *
773
- * Note: When the cache expires (reaches maxAge), it will attempt to fetch from database if available.
774
- * The refreshCache option is specifically for refreshing BEFORE expiry in a stateless manner.
775
- *
776
- * @default false
777
- */
778
- refreshCache?:
779
- | boolean
780
- | {
781
- /**
782
- * Time in seconds before expiry when the cache should be refreshed.
783
- * For example, if maxAge is 300 (5 minutes) and updateAge is 60,
784
- * the cache will be refreshed when it has 60 seconds left before expiry.
785
- *
786
- * @default 20% of maxAge
787
- */
788
- updateAge?: number;
789
- };
790
- /**
791
- * Version of the cookie cache
792
- *
793
- * If a cookie cache version is changed, all existing cookie caches with the old version
794
- * will be invalidated.
795
- *
796
- * It can be a string or a function that returns a string or a promise that returns a string.
797
- * If it's a function, it will be called with the session and user data
798
- *
799
- * @default "1"
800
- */
801
- version?:
802
- | string
803
- | ((
804
- session: Session & Record<string, any>,
805
- user: User & Record<string, any>
806
- ) => string)
807
- | ((
808
- session: Session & Record<string, any>,
809
- user: User & Record<string, any>
810
- ) => Promise<string>);
811
- };
812
- /**
813
- * The age of the session to consider it fresh.
814
- *
815
- * This is used to check if the session is fresh
816
- * for sensitive operations. (e.g. deleting an account)
817
- *
818
- * If the session is not fresh, the user should be prompted
819
- * to sign in again.
820
- *
821
- * If set to 0, the session will be considered fresh every time. (⚠︎ not recommended)
822
- *
823
- * @default 1 day (60 * 60 * 24)
824
- */
825
- freshAge?: number;
826
- }
827
- | undefined;
828
- account?:
829
- | {
830
- /**
831
- * The model name for the account. Defaults to "account".
832
- */
833
- modelName?: string;
834
- /**
835
- * Map fields
836
- */
837
- fields?: Partial<Record<keyof OmitId<Account>, string>>;
838
- /**
839
- * Additional fields for the account
840
- */
841
- additionalFields?: {
842
- [key: string]: DBFieldAttribute;
843
- };
844
- /**
845
- * When enabled (true), the user account data (accessToken, idToken, refreshToken, etc.)
846
- * will be updated on sign in with the latest data from the provider.
847
- *
848
- * @default true
849
- */
850
- updateAccountOnSignIn?: boolean;
851
- /**
852
- * Configuration for account linking.
853
- */
854
- accountLinking?: {
855
- /**
856
- * Enable account linking
857
- *
858
- * @default true
859
- */
860
- enabled?: boolean;
861
- /**
862
- * List of trusted providers
863
- */
864
- trustedProviders?: Array<
865
- LiteralUnion<SocialProviderList[number] | "email-password", string>
866
- >;
867
- /**
868
- * If enabled (true), this will allow users to manually linking accounts with different email addresses than the main user.
869
- *
870
- * @default false
871
- *
872
- * ⚠️ Warning: enabling this might lead to account takeovers, so proceed with caution.
873
- */
874
- allowDifferentEmails?: boolean;
875
- /**
876
- * If enabled (true), this will allow users to unlink all accounts.
877
- *
878
- * @default false
879
- */
880
- allowUnlinkingAll?: boolean;
881
- /**
882
- * If enabled (true), this will update the user information based on the newly linked account
883
- *
884
- * @default false
885
- */
886
- updateUserInfoOnLink?: boolean;
887
- };
888
- /**
889
- * Encrypt OAuth tokens
890
- *
891
- * By default, OAuth tokens (access tokens, refresh tokens, ID tokens) are stored in plain text in the database.
892
- * This poses a security risk if your database is compromised, as attackers could gain access to user accounts
893
- * on external services.
894
- *
895
- * When enabled, tokens are encrypted using AES-256-GCM before storage, providing protection against:
896
- * - Database breaches and unauthorized access to raw token data
897
- * - Internal threats from database administrators or compromised credentials
898
- * - Token exposure in database backups and logs
899
- * @default false
900
- */
901
- encryptOAuthTokens?: boolean;
902
- }
903
- | undefined;
904
- /**
905
- * Verification configuration
906
- */
907
- verification?:
908
- | {
909
- /**
910
- * Change the modelName of the verification table
911
- */
912
- modelName?: string;
913
- /**
914
- * Map verification fields
915
- */
916
- fields?: Partial<Record<keyof OmitId<Verification>, string>>;
917
- /**
918
- * disable cleaning up expired values when a verification value is
919
- * fetched
920
- */
921
- disableCleanup?: boolean;
922
- }
923
- | undefined;
924
- /**
925
- * List of trusted origins.
926
- */
927
- trustedOrigins?:
928
- | (string[] | ((request: Request) => string[] | Promise<string[]>))
929
- | undefined;
930
- /**
931
- * Rate limiting configuration
932
- */
933
- rateLimit?: PayvoAuthRateLimitOptions | undefined;
934
- /**
935
- * Advanced options
936
- */
937
- advanced?:
938
- | (PayvoAuthAdvancedOptions & {
939
- /**
940
- * @deprecated Please use `database.generateId` instead.
941
- */
942
- generateId?: never;
943
- })
944
- | undefined;
945
- logger?: Logger | undefined;
946
- /**
947
- * allows you to define custom hooks that can be
948
- * executed during lifecycle of core database
949
- * operations.
950
- */
951
- databaseHooks?:
952
- | {
953
- /**
954
- * User hooks
955
- */
956
- user?: {
957
- create?: {
958
- /**
959
- * Hook that is called before a user is created.
960
- * if the hook returns false, the user will not be created.
961
- * If the hook returns an object, it'll be used instead of the original data
962
- */
963
- before?: (
964
- user: User & Record<string, unknown>,
965
- context?: GenericEndpointContext
966
- ) => Promise<
967
- | boolean
968
- | void
969
- | {
970
- data: Optional<User> & Record<string, any>;
971
- }
972
- >;
973
- /**
974
- * Hook that is called after a user is created.
975
- */
976
- after?: (
977
- user: User & Record<string, unknown>,
978
- context?: GenericEndpointContext
979
- ) => Promise<void>;
980
- };
981
- update?: {
982
- /**
983
- * Hook that is called before a user is updated.
984
- * if the hook returns false, the user will not be updated.
985
- * If the hook returns an object, it'll be used instead of the original data
986
- */
987
- before?: (
988
- user: Partial<User> & Record<string, unknown>,
989
- context?: GenericEndpointContext
990
- ) => Promise<
991
- | boolean
992
- | void
993
- | {
994
- data: Optional<User & Record<string, any>>;
995
- }
996
- >;
997
- /**
998
- * Hook that is called after a user is updated.
999
- */
1000
- after?: (
1001
- user: User & Record<string, unknown>,
1002
- context?: GenericEndpointContext
1003
- ) => Promise<void>;
1004
- };
1005
- delete?: {
1006
- /**
1007
- * Hook that is called before a user is deleted.
1008
- * if the hook returns false, the user will not be deleted.
1009
- */
1010
- before?: (
1011
- user: User & Record<string, unknown>,
1012
- context?: GenericEndpointContext
1013
- ) => Promise<boolean | void>;
1014
- /**
1015
- * Hook that is called after a user is deleted.
1016
- */
1017
- after?: (
1018
- user: User & Record<string, unknown>,
1019
- context?: GenericEndpointContext
1020
- ) => Promise<void>;
1021
- };
1022
- };
1023
- /**
1024
- * Session Hook
1025
- */
1026
- session?: {
1027
- create?: {
1028
- /**
1029
- * Hook that is called before a session is created.
1030
- * if the hook returns false, the session will not be created.
1031
- * If the hook returns an object, it'll be used instead of the original data
1032
- */
1033
- before?: (
1034
- session: Session & Record<string, unknown>,
1035
- context?: GenericEndpointContext
1036
- ) => Promise<
1037
- | boolean
1038
- | void
1039
- | {
1040
- data: Optional<Session> & Record<string, any>;
1041
- }
1042
- >;
1043
- /**
1044
- * Hook that is called after a session is created.
1045
- */
1046
- after?: (
1047
- session: Session & Record<string, unknown>,
1048
- context?: GenericEndpointContext
1049
- ) => Promise<void>;
1050
- };
1051
- /**
1052
- * Update hook
1053
- */
1054
- update?: {
1055
- /**
1056
- * Hook that is called before a user is updated.
1057
- * if the hook returns false, the session will not be updated.
1058
- * If the hook returns an object, it'll be used instead of the original data
1059
- */
1060
- before?: (
1061
- session: Partial<Session> & Record<string, unknown>,
1062
- context?: GenericEndpointContext
1063
- ) => Promise<
1064
- | boolean
1065
- | void
1066
- | {
1067
- data: Optional<Session & Record<string, any>>;
1068
- }
1069
- >;
1070
- /**
1071
- * Hook that is called after a session is updated.
1072
- */
1073
- after?: (
1074
- session: Session & Record<string, unknown>,
1075
- context?: GenericEndpointContext
1076
- ) => Promise<void>;
1077
- };
1078
- delete?: {
1079
- /**
1080
- * Hook that is called before a session is deleted.
1081
- * if the hook returns false, the session will not be deleted.
1082
- */
1083
- before?: (
1084
- session: Session & Record<string, unknown>,
1085
- context?: GenericEndpointContext
1086
- ) => Promise<boolean | void>;
1087
- /**
1088
- * Hook that is called after a session is deleted.
1089
- */
1090
- after?: (
1091
- session: Session & Record<string, unknown>,
1092
- context?: GenericEndpointContext
1093
- ) => Promise<void>;
1094
- };
1095
- };
1096
- /**
1097
- * Account Hook
1098
- */
1099
- account?: {
1100
- create?: {
1101
- /**
1102
- * Hook that is called before a account is created.
1103
- * If the hook returns false, the account will not be created.
1104
- * If the hook returns an object, it'll be used instead of the original data
1105
- */
1106
- before?: (
1107
- account: Account,
1108
- context?: GenericEndpointContext
1109
- ) => Promise<
1110
- | boolean
1111
- | void
1112
- | {
1113
- data: Optional<Account> & Record<string, any>;
1114
- }
1115
- >;
1116
- /**
1117
- * Hook that is called after a account is created.
1118
- */
1119
- after?: (
1120
- account: Account,
1121
- context?: GenericEndpointContext
1122
- ) => Promise<void>;
1123
- };
1124
- /**
1125
- * Update hook
1126
- */
1127
- update?: {
1128
- /**
1129
- * Hook that is called before a account is update.
1130
- * If the hook returns false, the user will not be updated.
1131
- * If the hook returns an object, it'll be used instead of the original data
1132
- */
1133
- before?: (
1134
- account: Partial<Account> & Record<string, unknown>,
1135
- context?: GenericEndpointContext
1136
- ) => Promise<
1137
- | boolean
1138
- | void
1139
- | {
1140
- data: Optional<Account & Record<string, any>>;
1141
- }
1142
- >;
1143
- /**
1144
- * Hook that is called after a account is updated.
1145
- */
1146
- after?: (
1147
- account: Account & Record<string, unknown>,
1148
- context?: GenericEndpointContext
1149
- ) => Promise<void>;
1150
- };
1151
- delete?: {
1152
- /**
1153
- * Hook that is called before an account is deleted.
1154
- * if the hook returns false, the account will not be deleted.
1155
- */
1156
- before?: (
1157
- account: Account & Record<string, unknown>,
1158
- context?: GenericEndpointContext
1159
- ) => Promise<boolean | void>;
1160
- /**
1161
- * Hook that is called after an account is deleted.
1162
- */
1163
- after?: (
1164
- account: Account & Record<string, unknown>,
1165
- context?: GenericEndpointContext
1166
- ) => Promise<void>;
1167
- };
1168
- };
1169
- /**
1170
- * Verification Hook
1171
- */
1172
- verification?: {
1173
- create?: {
1174
- /**
1175
- * Hook that is called before a verification is created.
1176
- * if the hook returns false, the verification will not be created.
1177
- * If the hook returns an object, it'll be used instead of the original data
1178
- */
1179
- before?: (
1180
- verification: Verification & Record<string, unknown>,
1181
- context?: GenericEndpointContext
1182
- ) => Promise<
1183
- | boolean
1184
- | void
1185
- | {
1186
- data: Optional<Verification> & Record<string, any>;
1187
- }
1188
- >;
1189
- /**
1190
- * Hook that is called after a verification is created.
1191
- */
1192
- after?: (
1193
- verification: Verification & Record<string, unknown>,
1194
- context?: GenericEndpointContext
1195
- ) => Promise<void>;
1196
- };
1197
- update?: {
1198
- /**
1199
- * Hook that is called before a verification is updated.
1200
- * if the hook returns false, the verification will not be updated.
1201
- * If the hook returns an object, it'll be used instead of the original data
1202
- */
1203
- before?: (
1204
- verification: Partial<Verification> & Record<string, unknown>,
1205
- context?: GenericEndpointContext
1206
- ) => Promise<
1207
- | boolean
1208
- | void
1209
- | {
1210
- data: Optional<Verification & Record<string, any>>;
1211
- }
1212
- >;
1213
- /**
1214
- * Hook that is called after a verification is updated.
1215
- */
1216
- after?: (
1217
- verification: Verification & Record<string, unknown>,
1218
- context?: GenericEndpointContext
1219
- ) => Promise<void>;
1220
- };
1221
- delete?: {
1222
- /**
1223
- * Hook that is called before a verification is deleted.
1224
- * if the hook returns false, the verification will not be deleted.
1225
- */
1226
- before?: (
1227
- verification: Verification & Record<string, unknown>,
1228
- context?: GenericEndpointContext
1229
- ) => Promise<boolean | void>;
1230
- /**
1231
- * Hook that is called after a verification is deleted.
1232
- */
1233
- after?: (
1234
- verification: Verification & Record<string, unknown>,
1235
- context?: GenericEndpointContext
1236
- ) => Promise<void>;
1237
- };
1238
- };
1239
- }
1240
- | undefined;
1241
- /**
1242
- * API error handling
1243
- */
1244
- onAPIError?:
1245
- | {
1246
- /**
1247
- * Throw an error on API error
1248
- *
1249
- * @default false
1250
- */
1251
- throw?: boolean;
1252
- /**
1253
- * Custom error handler
1254
- *
1255
- * @param error
1256
- * @param ctx - Auth context
1257
- */
1258
- onError?: (error: unknown, ctx: AuthContext) => void | Promise<void>;
1259
- /**
1260
- * The URL to redirect to on error
1261
- *
1262
- * When errorURL is provided, the error will be added to the URL as a query parameter
1263
- * and the user will be redirected to the errorURL.
1264
- *
1265
- * @default - "/api/v1/auth/error"
1266
- */
1267
- errorURL?: string;
1268
- /**
1269
- * Configure the default error page provided by Better-Auth
1270
- * Start your dev server and go to /api/v1/auth/error to see the error page.
1271
- */
1272
- customizeDefaultErrorPage?: {
1273
- colors?: {
1274
- background?: string;
1275
- foreground?: string;
1276
- primary?: string;
1277
- primaryForeground?: string;
1278
- mutedForeground?: string;
1279
- border?: string;
1280
- destructive?: string;
1281
- titleBorder?: string;
1282
- titleColor?: string;
1283
- gridColor?: string;
1284
- cardBackground?: string;
1285
- cornerBorder?: string;
1286
- };
1287
- size?: {
1288
- radiusSm?: string;
1289
- radiusMd?: string;
1290
- radiusLg?: string;
1291
- textSm?: string;
1292
- text2xl?: string;
1293
- text4xl?: string;
1294
- text6xl?: string;
1295
- };
1296
- font?: {
1297
- defaultFamily?: string;
1298
- monoFamily?: string;
1299
- };
1300
- disableTitleBorder?: boolean;
1301
- disableCornerDecorations?: boolean;
1302
- disableBackgroundGrid?: boolean;
1303
- };
1304
- }
1305
- | undefined;
1306
- /**
1307
- * Hooks
1308
- */
1309
- hooks?:
1310
- | {
1311
- /**
1312
- * Before a request is processed
1313
- */
1314
- before?: AuthMiddleware;
1315
- /**
1316
- * After a request is processed
1317
- */
1318
- after?: AuthMiddleware;
1319
- }
1320
- | undefined;
1321
- /**
1322
- * Disabled paths
1323
- *
1324
- * Paths you want to disable.
1325
- */
1326
- disabledPaths?: string[] | undefined;
1327
- /**
1328
- * Telemetry configuration
1329
- */
1330
- telemetry?:
1331
- | {
1332
- /**
1333
- * Enable telemetry collection
1334
- *
1335
- * @default false
1336
- */
1337
- enabled?: boolean;
1338
- /**
1339
- * Enable debug mode
1340
- *
1341
- * @default false
1342
- */
1343
- debug?: boolean;
1344
- }
1345
- | undefined;
1346
- };