@hammadj/better-auth-core 1.5.0-beta.9

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