better-auth 1.7.0-beta.4 → 1.7.0-beta.6

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 (312) hide show
  1. package/dist/_virtual/_rolldown/runtime.mjs +1 -10
  2. package/dist/api/dispatch.d.mts +34 -0
  3. package/dist/api/dispatch.mjs +272 -0
  4. package/dist/api/index.d.mts +29 -12
  5. package/dist/api/index.mjs +6 -6
  6. package/dist/api/middlewares/origin-check.mjs +6 -1
  7. package/dist/api/rate-limiter/index.mjs +213 -95
  8. package/dist/api/routes/account.d.mts +10 -4
  9. package/dist/api/routes/account.mjs +93 -87
  10. package/dist/api/routes/callback.mjs +64 -40
  11. package/dist/api/routes/email-verification.mjs +19 -6
  12. package/dist/api/routes/index.d.mts +1 -1
  13. package/dist/api/routes/password.mjs +3 -4
  14. package/dist/api/routes/session.d.mts +12 -1
  15. package/dist/api/routes/session.mjs +98 -85
  16. package/dist/api/routes/sign-in.d.mts +2 -0
  17. package/dist/api/routes/sign-in.mjs +44 -23
  18. package/dist/api/routes/sign-up.mjs +41 -35
  19. package/dist/api/routes/update-session.mjs +9 -4
  20. package/dist/api/routes/update-user.mjs +10 -12
  21. package/dist/api/state/oauth.d.mts +38 -2
  22. package/dist/api/state/oauth.mjs +35 -2
  23. package/dist/api/to-auth-endpoints.mjs +14 -265
  24. package/dist/auth/base.mjs +11 -7
  25. package/dist/auth/trusted-origins.mjs +60 -1
  26. package/dist/client/config.d.mts +88 -0
  27. package/dist/client/equality.d.mts +19 -0
  28. package/dist/client/equality.mjs +42 -0
  29. package/dist/client/index.d.mts +5 -4
  30. package/dist/client/index.mjs +2 -1
  31. package/dist/client/lynx/index.d.mts +21 -117
  32. package/dist/client/path-to-object.d.mts +5 -2
  33. package/dist/client/plugins/index.d.mts +4 -3
  34. package/dist/client/plugins/index.mjs +4 -2
  35. package/dist/client/query.d.mts +4 -3
  36. package/dist/client/query.mjs +27 -17
  37. package/dist/client/react/index.d.mts +21 -117
  38. package/dist/client/session-atom.d.mts +11 -0
  39. package/dist/client/session-atom.mjs +129 -4
  40. package/dist/client/session-refresh.d.mts +3 -18
  41. package/dist/client/session-refresh.mjs +38 -49
  42. package/dist/client/solid/index.d.mts +20 -111
  43. package/dist/client/svelte/index.d.mts +21 -117
  44. package/dist/client/types.d.mts +27 -16
  45. package/dist/client/vanilla.d.mts +20 -117
  46. package/dist/client/vue/index.d.mts +37 -144
  47. package/dist/context/create-context.mjs +15 -3
  48. package/dist/context/helpers.mjs +5 -4
  49. package/dist/context/store-capabilities.mjs +12 -0
  50. package/dist/cookies/cookie-utils.mjs +2 -2
  51. package/dist/cookies/index.d.mts +7 -0
  52. package/dist/cookies/index.mjs +55 -20
  53. package/dist/cookies/session-store.d.mts +1 -18
  54. package/dist/cookies/session-store.mjs +42 -51
  55. package/dist/db/get-migration.mjs +34 -1
  56. package/dist/db/internal-adapter.mjs +126 -32
  57. package/dist/db/schema.d.mts +1 -1
  58. package/dist/db/to-zod.d.mts +2 -2
  59. package/dist/db/to-zod.mjs +1 -1
  60. package/dist/index.d.mts +3 -3
  61. package/dist/oauth2/errors.mjs +21 -1
  62. package/dist/oauth2/index.d.mts +6 -4
  63. package/dist/oauth2/index.mjs +5 -3
  64. package/dist/oauth2/persist-account.d.mts +80 -0
  65. package/dist/oauth2/persist-account.mjs +84 -0
  66. package/dist/oauth2/resolve-account.d.mts +126 -0
  67. package/dist/oauth2/resolve-account.mjs +128 -0
  68. package/dist/oauth2/sign-in-with-oauth-identity.d.mts +83 -0
  69. package/dist/oauth2/sign-in-with-oauth-identity.mjs +133 -0
  70. package/dist/oauth2/state.d.mts +31 -5
  71. package/dist/oauth2/state.mjs +11 -7
  72. package/dist/oauth2/{utils.d.mts → token-encryption.d.mts} +1 -1
  73. package/dist/oauth2/{utils.mjs → token-encryption.mjs} +1 -1
  74. package/dist/{packages/better-auth/package.mjs → package.mjs} +1 -1
  75. package/dist/plugins/access/access.mjs +49 -19
  76. package/dist/plugins/admin/access/statement.d.mts +10 -10
  77. package/dist/plugins/admin/access/statement.mjs +2 -0
  78. package/dist/plugins/admin/admin.d.mts +6 -3
  79. package/dist/plugins/admin/client.d.mts +6 -4
  80. package/dist/plugins/admin/error-codes.d.mts +2 -0
  81. package/dist/plugins/admin/error-codes.mjs +3 -1
  82. package/dist/plugins/admin/routes.mjs +77 -6
  83. package/dist/plugins/admin/schema.d.mts +1 -0
  84. package/dist/plugins/admin/schema.mjs +2 -1
  85. package/dist/plugins/anonymous/index.d.mts +4 -0
  86. package/dist/plugins/anonymous/index.mjs +90 -47
  87. package/dist/plugins/captcha/constants.mjs +8 -1
  88. package/dist/plugins/captcha/index.mjs +17 -13
  89. package/dist/plugins/captcha/types.d.mts +25 -0
  90. package/dist/plugins/captcha/verify-handlers/captchafox.mjs +2 -0
  91. package/dist/plugins/captcha/verify-handlers/cloudflare-turnstile.mjs +7 -2
  92. package/dist/plugins/captcha/verify-handlers/google-recaptcha.mjs +7 -2
  93. package/dist/plugins/captcha/verify-handlers/h-captcha.mjs +2 -0
  94. package/dist/plugins/device-authorization/index.d.mts +3 -0
  95. package/dist/plugins/device-authorization/routes.mjs +123 -100
  96. package/dist/plugins/email-otp/index.mjs +1 -1
  97. package/dist/plugins/email-otp/otp-token.mjs +1 -1
  98. package/dist/plugins/email-otp/routes.mjs +25 -55
  99. package/dist/plugins/generic-oauth/index.d.mts +4 -4
  100. package/dist/plugins/generic-oauth/index.mjs +43 -15
  101. package/dist/plugins/generic-oauth/types.d.mts +21 -3
  102. package/dist/plugins/haveibeenpwned/index.d.mts +1 -1
  103. package/dist/plugins/haveibeenpwned/index.mjs +5 -1
  104. package/dist/plugins/index.d.mts +7 -6
  105. package/dist/plugins/index.mjs +6 -5
  106. package/dist/plugins/jwt/adapter.mjs +21 -2
  107. package/dist/plugins/jwt/cookie-cache.mjs +117 -0
  108. package/dist/plugins/jwt/index.d.mts +8 -0
  109. package/dist/plugins/jwt/index.mjs +6 -6
  110. package/dist/plugins/jwt/schema.d.mts +8 -0
  111. package/dist/plugins/jwt/schema.mjs +8 -0
  112. package/dist/plugins/jwt/sign.d.mts +62 -2
  113. package/dist/plugins/jwt/sign.mjs +53 -6
  114. package/dist/plugins/jwt/types.d.mts +45 -1
  115. package/dist/plugins/jwt/utils.mjs +6 -3
  116. package/dist/plugins/last-login-method/client.d.mts +10 -0
  117. package/dist/plugins/last-login-method/client.mjs +4 -1
  118. package/dist/plugins/magic-link/index.mjs +14 -6
  119. package/dist/plugins/multi-session/index.mjs +7 -5
  120. package/dist/plugins/oauth-popup/client.d.mts +82 -0
  121. package/dist/plugins/oauth-popup/client.mjs +203 -0
  122. package/dist/plugins/oauth-popup/constants.d.mts +11 -0
  123. package/dist/plugins/oauth-popup/constants.mjs +11 -0
  124. package/dist/plugins/oauth-popup/error-codes.d.mts +11 -0
  125. package/dist/plugins/oauth-popup/error-codes.mjs +10 -0
  126. package/dist/plugins/oauth-popup/index.d.mts +67 -0
  127. package/dist/plugins/oauth-popup/index.mjs +228 -0
  128. package/dist/plugins/oauth-popup/types.d.mts +30 -0
  129. package/dist/plugins/oauth-proxy/index.mjs +33 -9
  130. package/dist/plugins/oauth-proxy/utils.mjs +16 -2
  131. package/dist/plugins/one-tap/client.mjs +12 -6
  132. package/dist/plugins/one-tap/index.d.mts +1 -2
  133. package/dist/plugins/one-tap/index.mjs +39 -18
  134. package/dist/plugins/one-time-token/index.mjs +1 -3
  135. package/dist/plugins/open-api/generator.d.mts +71 -59
  136. package/dist/plugins/open-api/generator.mjs +246 -108
  137. package/dist/plugins/open-api/index.d.mts +2 -2
  138. package/dist/plugins/organization/adapter.d.mts +33 -7
  139. package/dist/plugins/organization/adapter.mjs +221 -44
  140. package/dist/plugins/organization/client.d.mts +4 -4
  141. package/dist/plugins/organization/organization.mjs +18 -0
  142. package/dist/plugins/organization/routes/crud-access-control.d.mts +1 -1
  143. package/dist/plugins/organization/routes/crud-access-control.mjs +1 -1
  144. package/dist/plugins/organization/routes/crud-invites.mjs +85 -34
  145. package/dist/plugins/organization/routes/crud-members.mjs +59 -6
  146. package/dist/plugins/organization/routes/crud-team.d.mts +5 -8
  147. package/dist/plugins/organization/routes/crud-team.mjs +53 -4
  148. package/dist/plugins/organization/schema.d.mts +16 -0
  149. package/dist/plugins/organization/types.d.mts +20 -13
  150. package/dist/plugins/phone-number/index.d.mts +12 -0
  151. package/dist/plugins/phone-number/index.mjs +2 -1
  152. package/dist/plugins/phone-number/routes.mjs +81 -45
  153. package/dist/plugins/siwe/index.mjs +31 -4
  154. package/dist/plugins/siwe/parse-message.mjs +60 -0
  155. package/dist/plugins/test-utils/db-helpers.mjs +1 -1
  156. package/dist/plugins/two-factor/backup-codes/index.mjs +5 -4
  157. package/dist/plugins/two-factor/index.mjs +9 -1
  158. package/dist/plugins/two-factor/otp/index.mjs +11 -13
  159. package/dist/plugins/two-factor/totp/index.mjs +1 -1
  160. package/dist/plugins/two-factor/verify-two-factor.mjs +6 -2
  161. package/dist/plugins/username/index.mjs +6 -6
  162. package/dist/state.d.mts +17 -1
  163. package/dist/state.mjs +6 -3
  164. package/dist/test-utils/http-test-instance.d.mts +35 -8
  165. package/dist/test-utils/http-test-instance.mjs +49 -8
  166. package/dist/test-utils/test-instance.d.mts +3 -16065
  167. package/dist/types/index.d.mts +2 -2
  168. package/dist/utils/index.d.mts +1 -1
  169. package/dist/utils/validate-user-info.mjs +44 -0
  170. package/dist/version.mjs +1 -1
  171. package/package.json +11 -36
  172. package/dist/node_modules/.pnpm/clipboardy@4.0.0/node_modules/clipboardy/index.mjs +0 -32
  173. package/dist/node_modules/.pnpm/clipboardy@4.0.0/node_modules/clipboardy/lib/linux.mjs +0 -55
  174. package/dist/node_modules/.pnpm/clipboardy@4.0.0/node_modules/clipboardy/lib/macos.mjs +0 -26
  175. package/dist/node_modules/.pnpm/clipboardy@4.0.0/node_modules/clipboardy/lib/termux.mjs +0 -39
  176. package/dist/node_modules/.pnpm/clipboardy@4.0.0/node_modules/clipboardy/lib/windows.mjs +0 -19
  177. package/dist/node_modules/.pnpm/consola@3.4.2/node_modules/consola/dist/chunks/prompt.mjs +0 -845
  178. package/dist/node_modules/.pnpm/consola@3.4.2/node_modules/consola/dist/core.mjs +0 -386
  179. package/dist/node_modules/.pnpm/consola@3.4.2/node_modules/consola/dist/index.mjs +0 -320
  180. package/dist/node_modules/.pnpm/consola@3.4.2/node_modules/consola/dist/shared/consola.DRwqZj3T.mjs +0 -62
  181. package/dist/node_modules/.pnpm/consola@3.4.2/node_modules/consola/dist/shared/consola.DXBYu-KD.mjs +0 -190
  182. package/dist/node_modules/.pnpm/consola@3.4.2/node_modules/consola/dist/utils.mjs +0 -2
  183. package/dist/node_modules/.pnpm/cross-spawn@7.0.6/node_modules/cross-spawn/index.mjs +0 -29
  184. package/dist/node_modules/.pnpm/cross-spawn@7.0.6/node_modules/cross-spawn/lib/enoent.mjs +0 -42
  185. package/dist/node_modules/.pnpm/cross-spawn@7.0.6/node_modules/cross-spawn/lib/parse.mjs +0 -67
  186. package/dist/node_modules/.pnpm/cross-spawn@7.0.6/node_modules/cross-spawn/lib/util/escape.mjs +0 -23
  187. package/dist/node_modules/.pnpm/cross-spawn@7.0.6/node_modules/cross-spawn/lib/util/readShebang.mjs +0 -22
  188. package/dist/node_modules/.pnpm/cross-spawn@7.0.6/node_modules/cross-spawn/lib/util/resolveCommand.mjs +0 -36
  189. package/dist/node_modules/.pnpm/crossws@0.3.5/node_modules/crossws/dist/adapters/node.d.mts +0 -292
  190. package/dist/node_modules/.pnpm/crossws@0.3.5/node_modules/crossws/dist/adapters/node.mjs +0 -127
  191. package/dist/node_modules/.pnpm/crossws@0.3.5/node_modules/crossws/dist/index.d.mts +0 -145
  192. package/dist/node_modules/.pnpm/crossws@0.3.5/node_modules/crossws/dist/shared/crossws.BQXMA5bH.d.mts +0 -298
  193. package/dist/node_modules/.pnpm/crossws@0.3.5/node_modules/crossws/dist/shared/crossws.By9qWDAI.mjs +0 -9
  194. package/dist/node_modules/.pnpm/crossws@0.3.5/node_modules/crossws/dist/shared/crossws.CipVM6lf.mjs +0 -3549
  195. package/dist/node_modules/.pnpm/crossws@0.3.5/node_modules/crossws/dist/shared/crossws.D9ehKjSh.mjs +0 -66
  196. package/dist/node_modules/.pnpm/crossws@0.3.5/node_modules/crossws/dist/shared/crossws.DfCzGthR.mjs +0 -227
  197. package/dist/node_modules/.pnpm/execa@8.0.1/node_modules/execa/index.mjs +0 -224
  198. package/dist/node_modules/.pnpm/execa@8.0.1/node_modules/execa/lib/command.mjs +0 -52
  199. package/dist/node_modules/.pnpm/execa@8.0.1/node_modules/execa/lib/error.mjs +0 -54
  200. package/dist/node_modules/.pnpm/execa@8.0.1/node_modules/execa/lib/kill.mjs +0 -62
  201. package/dist/node_modules/.pnpm/execa@8.0.1/node_modules/execa/lib/pipe.mjs +0 -26
  202. package/dist/node_modules/.pnpm/execa@8.0.1/node_modules/execa/lib/promise.mjs +0 -32
  203. package/dist/node_modules/.pnpm/execa@8.0.1/node_modules/execa/lib/stdio.mjs +0 -19
  204. package/dist/node_modules/.pnpm/execa@8.0.1/node_modules/execa/lib/stream.mjs +0 -98
  205. package/dist/node_modules/.pnpm/execa@8.0.1/node_modules/execa/lib/verbose.mjs +0 -15
  206. package/dist/node_modules/.pnpm/get-port-please@3.2.0/node_modules/get-port-please/dist/index.d.mts +0 -15
  207. package/dist/node_modules/.pnpm/get-port-please@3.2.0/node_modules/get-port-please/dist/index.mjs +0 -220
  208. package/dist/node_modules/.pnpm/get-stream@8.0.1/node_modules/get-stream/source/array-buffer.mjs +0 -54
  209. package/dist/node_modules/.pnpm/get-stream@8.0.1/node_modules/get-stream/source/array.mjs +0 -2
  210. package/dist/node_modules/.pnpm/get-stream@8.0.1/node_modules/get-stream/source/buffer.mjs +0 -14
  211. package/dist/node_modules/.pnpm/get-stream@8.0.1/node_modules/get-stream/source/contents.mjs +0 -76
  212. package/dist/node_modules/.pnpm/get-stream@8.0.1/node_modules/get-stream/source/index.mjs +0 -6
  213. package/dist/node_modules/.pnpm/get-stream@8.0.1/node_modules/get-stream/source/string.mjs +0 -35
  214. package/dist/node_modules/.pnpm/get-stream@8.0.1/node_modules/get-stream/source/utils.mjs +0 -10
  215. package/dist/node_modules/.pnpm/http-shutdown@1.2.2/node_modules/http-shutdown/index.mjs +0 -76
  216. package/dist/node_modules/.pnpm/human-signals@5.0.0/node_modules/human-signals/build/src/core.mjs +0 -274
  217. package/dist/node_modules/.pnpm/human-signals@5.0.0/node_modules/human-signals/build/src/main.mjs +0 -44
  218. package/dist/node_modules/.pnpm/human-signals@5.0.0/node_modules/human-signals/build/src/realtime.mjs +0 -15
  219. package/dist/node_modules/.pnpm/human-signals@5.0.0/node_modules/human-signals/build/src/signals.mjs +0 -23
  220. package/dist/node_modules/.pnpm/is-docker@3.0.0/node_modules/is-docker/index.mjs +0 -24
  221. package/dist/node_modules/.pnpm/is-inside-container@1.0.0/node_modules/is-inside-container/index.mjs +0 -18
  222. package/dist/node_modules/.pnpm/is-stream@3.0.0/node_modules/is-stream/index.mjs +0 -9
  223. package/dist/node_modules/.pnpm/is-wsl@3.1.1/node_modules/is-wsl/index.mjs +0 -20
  224. package/dist/node_modules/.pnpm/is64bit@2.0.0/node_modules/is64bit/index.mjs +0 -13
  225. package/dist/node_modules/.pnpm/isexe@2.0.0/node_modules/isexe/index.mjs +0 -47
  226. package/dist/node_modules/.pnpm/isexe@2.0.0/node_modules/isexe/mode.mjs +0 -33
  227. package/dist/node_modules/.pnpm/isexe@2.0.0/node_modules/isexe/windows.mjs +0 -33
  228. package/dist/node_modules/.pnpm/listhen@1.9.0/node_modules/listhen/dist/chunks/xdg-open.mjs +0 -1070
  229. package/dist/node_modules/.pnpm/listhen@1.9.0/node_modules/listhen/dist/index.mjs +0 -619
  230. package/dist/node_modules/.pnpm/listhen@1.9.0/node_modules/listhen/dist/shared/listhen.1c46e31d.d.mts +0 -83
  231. package/dist/node_modules/.pnpm/merge-stream@2.0.0/node_modules/merge-stream/index.mjs +0 -38
  232. package/dist/node_modules/.pnpm/mimic-fn@4.0.0/node_modules/mimic-fn/index.mjs +0 -38
  233. package/dist/node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/aes.mjs +0 -597
  234. package/dist/node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/aesCipherSuites.mjs +0 -195
  235. package/dist/node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/asn1-validator.mjs +0 -76
  236. package/dist/node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/asn1.mjs +0 -967
  237. package/dist/node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/baseN.mjs +0 -137
  238. package/dist/node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/cipher.mjs +0 -186
  239. package/dist/node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/cipherModes.mjs +0 -597
  240. package/dist/node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/des.mjs +0 -1187
  241. package/dist/node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/ed25519.mjs +0 -1029
  242. package/dist/node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/forge.mjs +0 -15
  243. package/dist/node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/hmac.mjs +0 -107
  244. package/dist/node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/index.mjs +0 -66
  245. package/dist/node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/jsbn.mjs +0 -1334
  246. package/dist/node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/kem.mjs +0 -146
  247. package/dist/node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/log.mjs +0 -241
  248. package/dist/node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/md.all.mjs +0 -24
  249. package/dist/node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/md.mjs +0 -18
  250. package/dist/node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/md5.mjs +0 -324
  251. package/dist/node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/mgf.mjs +0 -20
  252. package/dist/node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/mgf1.mjs +0 -44
  253. package/dist/node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/oids.mjs +0 -154
  254. package/dist/node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/pbe.mjs +0 -815
  255. package/dist/node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/pbkdf2.mjs +0 -125
  256. package/dist/node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/pem.mjs +0 -175
  257. package/dist/node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/pkcs1.mjs +0 -200
  258. package/dist/node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/pkcs12.mjs +0 -724
  259. package/dist/node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/pkcs7.mjs +0 -642
  260. package/dist/node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/pkcs7asn1.mjs +0 -405
  261. package/dist/node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/pki.mjs +0 -101
  262. package/dist/node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/prime.mjs +0 -193
  263. package/dist/node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/prng.mjs +0 -290
  264. package/dist/node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/pss.mjs +0 -141
  265. package/dist/node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/random.mjs +0 -141
  266. package/dist/node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/rc2.mjs +0 -538
  267. package/dist/node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/rsa.mjs +0 -1309
  268. package/dist/node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/sha1.mjs +0 -230
  269. package/dist/node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/sha256.mjs +0 -267
  270. package/dist/node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/sha512.mjs +0 -413
  271. package/dist/node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/ssh.mjs +0 -194
  272. package/dist/node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/tls.mjs +0 -3655
  273. package/dist/node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/util.mjs +0 -2117
  274. package/dist/node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/x509.mjs +0 -2168
  275. package/dist/node_modules/.pnpm/npm-run-path@5.3.0/node_modules/npm-run-path/index.mjs +0 -34
  276. package/dist/node_modules/.pnpm/onetime@6.0.0/node_modules/onetime/index.mjs +0 -26
  277. package/dist/node_modules/.pnpm/path-key@3.1.1/node_modules/path-key/index.mjs +0 -14
  278. package/dist/node_modules/.pnpm/path-key@4.0.0/node_modules/path-key/index.mjs +0 -8
  279. package/dist/node_modules/.pnpm/pathe@1.1.2/node_modules/pathe/dist/shared/pathe.ff20891b.mjs +0 -176
  280. package/dist/node_modules/.pnpm/shebang-command@2.0.0/node_modules/shebang-command/index.mjs +0 -17
  281. package/dist/node_modules/.pnpm/shebang-regex@3.0.0/node_modules/shebang-regex/index.mjs +0 -8
  282. package/dist/node_modules/.pnpm/signal-exit@4.1.0/node_modules/signal-exit/dist/mjs/index.mjs +0 -169
  283. package/dist/node_modules/.pnpm/signal-exit@4.1.0/node_modules/signal-exit/dist/mjs/signals.mjs +0 -33
  284. package/dist/node_modules/.pnpm/std-env@3.10.0/node_modules/std-env/dist/index.mjs +0 -171
  285. package/dist/node_modules/.pnpm/strip-final-newline@3.0.0/node_modules/strip-final-newline/index.mjs +0 -10
  286. package/dist/node_modules/.pnpm/system-architecture@0.1.0/node_modules/system-architecture/index.mjs +0 -16
  287. package/dist/node_modules/.pnpm/uncrypto@0.1.3/node_modules/uncrypto/dist/crypto.node.mjs +0 -7
  288. package/dist/node_modules/.pnpm/untun@0.1.3/node_modules/untun/dist/chunks/index.mjs +0 -154
  289. package/dist/node_modules/.pnpm/untun@0.1.3/node_modules/untun/dist/index.mjs +0 -34
  290. package/dist/node_modules/.pnpm/uqr@0.1.2/node_modules/uqr/dist/index.mjs +0 -896
  291. package/dist/node_modules/.pnpm/which@2.0.2/node_modules/which/which.mjs +0 -76
  292. package/dist/oauth2/error-codes.mjs +0 -20
  293. package/dist/oauth2/link-account.d.mts +0 -72
  294. package/dist/oauth2/link-account.mjs +0 -164
  295. package/dist/plugins/mcp/authorize.mjs +0 -134
  296. package/dist/plugins/mcp/client/adapters.d.mts +0 -56
  297. package/dist/plugins/mcp/client/adapters.mjs +0 -117
  298. package/dist/plugins/mcp/client/index.d.mts +0 -44
  299. package/dist/plugins/mcp/client/index.mjs +0 -152
  300. package/dist/plugins/mcp/index.d.mts +0 -457
  301. package/dist/plugins/mcp/index.mjs +0 -770
  302. package/dist/plugins/oidc-provider/authorize.mjs +0 -204
  303. package/dist/plugins/oidc-provider/client.d.mts +0 -16
  304. package/dist/plugins/oidc-provider/client.mjs +0 -15
  305. package/dist/plugins/oidc-provider/error.mjs +0 -24
  306. package/dist/plugins/oidc-provider/index.d.mts +0 -705
  307. package/dist/plugins/oidc-provider/index.mjs +0 -1122
  308. package/dist/plugins/oidc-provider/schema.d.mts +0 -159
  309. package/dist/plugins/oidc-provider/schema.mjs +0 -129
  310. package/dist/plugins/oidc-provider/types.d.mts +0 -517
  311. package/dist/plugins/oidc-provider/utils/prompt.mjs +0 -16
  312. package/dist/plugins/oidc-provider/utils.mjs +0 -12
@@ -1,12 +1,8 @@
1
- import { createRequire } from "node:module";
2
1
  //#region \0rolldown/runtime.js
3
- var __create = Object.create;
4
2
  var __defProp = Object.defineProperty;
5
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
7
- var __getProtoOf = Object.getPrototypeOf;
8
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
9
- var __commonJSMin = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
10
6
  var __exportAll = (all, no_symbols) => {
11
7
  let target = {};
12
8
  for (var name in all) __defProp(target, name, {
@@ -27,10 +23,5 @@ var __copyProps = (to, from, except, desc) => {
27
23
  return to;
28
24
  };
29
25
  var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
30
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
31
- value: mod,
32
- enumerable: true
33
- }) : target, mod));
34
- var __require = /* @__PURE__ */ createRequire(import.meta.url);
35
26
  //#endregion
36
- export { __commonJSMin, __exportAll, __reExport, __require, __toESM };
27
+ export { __exportAll, __reExport };
@@ -0,0 +1,34 @@
1
+ import { AuthContext } from "@better-auth/core";
2
+ import { Endpoint, EndpointContext, InputContext } from "better-call";
3
+
4
+ //#region src/api/dispatch.d.ts
5
+ /**
6
+ * Input accepted by {@link dispatchAuthEndpoint}. `context` must already be a
7
+ * resolved `AuthContext`; the caller owns `baseURL` resolution. A fresh
8
+ * dispatch carries no `session` (the shared context has none), while a resumed
9
+ * dispatch carries the in-flight request's `session` through.
10
+ */
11
+ type DispatchContext = Partial<InputContext<string, any> & EndpointContext<string, any>> & {
12
+ context: AuthContext & {
13
+ returned?: unknown | undefined;
14
+ responseHeaders?: Headers | undefined;
15
+ };
16
+ operationId?: string | undefined;
17
+ };
18
+ /**
19
+ * Run a single endpoint through the configured `hooks.before` / `hooks.after`
20
+ * pipeline, normalizing the response, headers, and `APIError`s the same way a
21
+ * router or `auth.api.*` dispatch does.
22
+ *
23
+ * This is the canonical hook runner. The HTTP router and `auth.api.*` reach it
24
+ * through {@link toAuthEndpoints}. Plugins call it directly when they need to
25
+ * re-enter the pipeline on purpose, such as resuming `/oauth2/authorize` after
26
+ * a fresh sign-in. Calling an endpoint as a plain function deliberately skips
27
+ * hooks; `dispatchAuthEndpoint` is the supported way to opt back in.
28
+ *
29
+ * @param endpoint The endpoint to dispatch.
30
+ * @param input Input context whose `context` is an already-resolved `AuthContext`.
31
+ */
32
+ declare function dispatchAuthEndpoint(endpoint: Endpoint, input: DispatchContext): Promise<unknown>;
33
+ //#endregion
34
+ export { DispatchContext, dispatchAuthEndpoint };
@@ -0,0 +1,272 @@
1
+ import { isAPIError } from "../utils/is-api-error.mjs";
2
+ import { isRequestLike } from "../utils/url.mjs";
3
+ import { runWithEndpointContext } from "@better-auth/core/context";
4
+ import { shouldPublishLog } from "@better-auth/core/env";
5
+ import { APIError } from "@better-auth/core/error";
6
+ import { createDefu } from "defu";
7
+ import { ATTR_CONTEXT, ATTR_HOOK_TYPE, ATTR_HTTP_ROUTE, ATTR_OPERATION_ID, withSpan } from "@better-auth/core/instrumentation";
8
+ import { kAPIErrorHeaderSymbol, toResponse } from "better-call";
9
+ //#region src/api/dispatch.ts
10
+ const defuReplaceArrays = createDefu((obj, key, value) => {
11
+ if (Array.isArray(obj[key]) && Array.isArray(value)) {
12
+ obj[key] = value;
13
+ return true;
14
+ }
15
+ });
16
+ const hooksSourceWeakMap = /* @__PURE__ */ new WeakMap();
17
+ /**
18
+ * Resolves the operation id used for spans, preferring an explicit
19
+ * `operationId`, then the OpenAPI one, then the caller's `fallback` (the
20
+ * `auth.api.*` map key), and finally the route path.
21
+ */
22
+ function getOperationId(endpoint, fallback) {
23
+ const opts = endpoint.options;
24
+ return opts?.operationId ?? opts?.metadata?.openapi?.operationId ?? fallback ?? endpoint.path ?? "/:virtual";
25
+ }
26
+ /**
27
+ * Merge a set of response headers onto the dispatch's accumulator, appending
28
+ * `set-cookie` (multiple cookies are legal) and replacing everything else.
29
+ */
30
+ function mergeResponseHeaders(context, headers) {
31
+ if (!headers) return;
32
+ headers.forEach((value, key) => {
33
+ if (!context.responseHeaders) context.responseHeaders = new Headers({ [key]: value });
34
+ else if (key.toLowerCase() === "set-cookie") context.responseHeaders.append(key, value);
35
+ else context.responseHeaders.set(key, value);
36
+ });
37
+ }
38
+ /**
39
+ * Combine the two header sources an `APIError` can carry into one set:
40
+ * - `kAPIErrorHeaderSymbol`: `ctx.responseHeaders` accumulated via
41
+ * `c.setCookie` / `c.setHeader` before the throw.
42
+ * - `e.headers`: explicit headers on the error (e.g. `location` from
43
+ * `c.redirect`).
44
+ *
45
+ * `c.redirect()` reuses `ctx.responseHeaders` as `e.headers`, so when both
46
+ * point at the same object iterating each would duplicate every `set-cookie`;
47
+ * the identity check skips that copy. Explicit error headers override
48
+ * accumulated ones, while cookies from both accumulate.
49
+ */
50
+ function mergeAPIErrorHeaders(error) {
51
+ const ctxHeaders = error[kAPIErrorHeaderSymbol];
52
+ const errHeaders = error.headers && error.headers !== ctxHeaders ? new Headers(error.headers) : null;
53
+ if (!ctxHeaders && !errHeaders) return null;
54
+ const headers = new Headers();
55
+ ctxHeaders?.forEach((value, key) => {
56
+ headers.append(key, value);
57
+ });
58
+ errHeaders?.forEach((value, key) => {
59
+ if (key.toLowerCase() === "set-cookie") headers.append(key, value);
60
+ else headers.set(key, value);
61
+ });
62
+ return headers;
63
+ }
64
+ async function runBeforeHooks(context, hooks, endpoint, operationId) {
65
+ let modifiedContext = {};
66
+ for (const hook of hooks) {
67
+ let matched = false;
68
+ try {
69
+ matched = hook.matcher(context);
70
+ } catch (error) {
71
+ const hookSource = hooksSourceWeakMap.get(hook.handler) ?? "unknown";
72
+ context.context.logger.error(`An error occurred during ${hookSource} hook matcher execution:`, error);
73
+ throw new APIError("INTERNAL_SERVER_ERROR", { message: "An error occurred during hook matcher execution. Check the logs for more details." });
74
+ }
75
+ if (!matched) continue;
76
+ const hookSource = hooksSourceWeakMap.get(hook.handler) ?? "unknown";
77
+ const route = endpoint.path ?? "/:virtual";
78
+ const result = await withSpan(`hook before ${route} ${hookSource}`, {
79
+ [ATTR_HOOK_TYPE]: "before",
80
+ [ATTR_HTTP_ROUTE]: route,
81
+ [ATTR_CONTEXT]: hookSource,
82
+ [ATTR_OPERATION_ID]: operationId
83
+ }, () => hook.handler({
84
+ ...context,
85
+ returnHeaders: true
86
+ })).catch((e) => {
87
+ if (isAPIError(e) && shouldPublishLog(context.context.logger.level, "debug")) e.stack = e.errorStack;
88
+ throw e;
89
+ });
90
+ mergeResponseHeaders(context.context, result?.headers);
91
+ const hookReturn = result?.response;
92
+ if (hookReturn && typeof hookReturn === "object") {
93
+ if ("context" in hookReturn && typeof hookReturn.context === "object") {
94
+ const { headers, ...rest } = hookReturn.context;
95
+ if (headers instanceof Headers) if (modifiedContext.headers) headers.forEach((value, key) => {
96
+ modifiedContext.headers?.set(key, value);
97
+ });
98
+ else modifiedContext.headers = headers;
99
+ modifiedContext = defuReplaceArrays(rest, modifiedContext);
100
+ continue;
101
+ }
102
+ return hookReturn;
103
+ }
104
+ }
105
+ return { context: modifiedContext };
106
+ }
107
+ async function runAfterHooks(context, hooks, endpoint, operationId) {
108
+ for (const hook of hooks) {
109
+ if (!hook.matcher(context)) continue;
110
+ const hookSource = hooksSourceWeakMap.get(hook.handler) ?? "unknown";
111
+ const route = endpoint.path ?? "/:virtual";
112
+ const result = await withSpan(`hook after ${route} ${hookSource}`, {
113
+ [ATTR_HOOK_TYPE]: "after",
114
+ [ATTR_HTTP_ROUTE]: route,
115
+ [ATTR_CONTEXT]: hookSource,
116
+ [ATTR_OPERATION_ID]: operationId
117
+ }, () => hook.handler(context)).catch((e) => {
118
+ if (isAPIError(e)) {
119
+ if (shouldPublishLog(context.context.logger.level, "debug")) e.stack = e.errorStack;
120
+ return {
121
+ response: e,
122
+ headers: mergeAPIErrorHeaders(e)
123
+ };
124
+ }
125
+ throw e;
126
+ });
127
+ mergeResponseHeaders(context.context, result.headers);
128
+ if (result.response !== void 0) context.context.returned = result.response;
129
+ }
130
+ return {
131
+ response: context.context.returned,
132
+ headers: context.context.responseHeaders
133
+ };
134
+ }
135
+ function getHooks(authContext) {
136
+ const plugins = authContext.options.plugins || [];
137
+ const beforeHooks = [];
138
+ const afterHooks = [];
139
+ const beforeHookHandler = authContext.options.hooks?.before;
140
+ if (beforeHookHandler) {
141
+ hooksSourceWeakMap.set(beforeHookHandler, "user");
142
+ beforeHooks.push({
143
+ matcher: () => true,
144
+ handler: beforeHookHandler
145
+ });
146
+ }
147
+ const afterHookHandler = authContext.options.hooks?.after;
148
+ if (afterHookHandler) {
149
+ hooksSourceWeakMap.set(afterHookHandler, "user");
150
+ afterHooks.push({
151
+ matcher: () => true,
152
+ handler: afterHookHandler
153
+ });
154
+ }
155
+ const pluginBeforeHooks = plugins.flatMap((plugin) => (plugin.hooks?.before ?? []).map((h) => {
156
+ hooksSourceWeakMap.set(h.handler, `plugin:${plugin.id}`);
157
+ return h;
158
+ }));
159
+ const pluginAfterHooks = plugins.flatMap((plugin) => (plugin.hooks?.after ?? []).map((h) => {
160
+ hooksSourceWeakMap.set(h.handler, `plugin:${plugin.id}`);
161
+ return h;
162
+ }));
163
+ if (pluginBeforeHooks.length) beforeHooks.push(...pluginBeforeHooks);
164
+ if (pluginAfterHooks.length) afterHooks.push(...pluginAfterHooks);
165
+ return {
166
+ beforeHooks,
167
+ afterHooks
168
+ };
169
+ }
170
+ /**
171
+ * Run a single endpoint through the configured `hooks.before` / `hooks.after`
172
+ * pipeline, normalizing the response, headers, and `APIError`s the same way a
173
+ * router or `auth.api.*` dispatch does.
174
+ *
175
+ * This is the canonical hook runner. The HTTP router and `auth.api.*` reach it
176
+ * through {@link toAuthEndpoints}. Plugins call it directly when they need to
177
+ * re-enter the pipeline on purpose, such as resuming `/oauth2/authorize` after
178
+ * a fresh sign-in. Calling an endpoint as a plain function deliberately skips
179
+ * hooks; `dispatchAuthEndpoint` is the supported way to opt back in.
180
+ *
181
+ * @param endpoint The endpoint to dispatch.
182
+ * @param input Input context whose `context` is an already-resolved `AuthContext`.
183
+ */
184
+ async function dispatchAuthEndpoint(endpoint, input) {
185
+ const operationId = input.operationId ?? getOperationId(endpoint);
186
+ const route = endpoint.path ?? "/:virtual";
187
+ const endpointMethod = endpoint.options?.method;
188
+ const defaultMethod = Array.isArray(endpointMethod) ? endpointMethod[0] : endpointMethod;
189
+ const methodName = input.method ?? input.request?.method ?? defaultMethod ?? "?";
190
+ const shouldReturnResponse = input.asResponse ?? isRequestLike(input.request);
191
+ let internalContext = {
192
+ ...input,
193
+ context: {
194
+ ...input.context,
195
+ returned: void 0,
196
+ responseHeaders: void 0,
197
+ session: input.context.session ?? null
198
+ },
199
+ path: endpoint.path,
200
+ headers: input.headers ? new Headers(input.headers) : void 0
201
+ };
202
+ return withSpan(`${methodName} ${route}`, {
203
+ [ATTR_HTTP_ROUTE]: route,
204
+ [ATTR_OPERATION_ID]: operationId
205
+ }, async () => runWithEndpointContext(internalContext, async () => {
206
+ const { beforeHooks, afterHooks } = getHooks(internalContext.context);
207
+ const before = await runBeforeHooks(internalContext, beforeHooks, endpoint, operationId);
208
+ if ("context" in before && before.context && typeof before.context === "object") {
209
+ const { headers, ...rest } = before.context;
210
+ if (headers) {
211
+ if (!internalContext.headers) internalContext.headers = new Headers();
212
+ const requestHeaders = internalContext.headers;
213
+ headers.forEach((value, key) => {
214
+ requestHeaders.set(key, value);
215
+ });
216
+ }
217
+ internalContext = defuReplaceArrays(rest, internalContext);
218
+ } else if (before) {
219
+ const responseHeaders = internalContext.context.responseHeaders;
220
+ return shouldReturnResponse ? toResponse(before, { headers: responseHeaders }) : input.returnHeaders ? {
221
+ headers: responseHeaders,
222
+ response: before
223
+ } : before;
224
+ }
225
+ internalContext.asResponse = false;
226
+ internalContext.returnHeaders = true;
227
+ internalContext.returnStatus = true;
228
+ const result = await runWithEndpointContext(internalContext, () => withSpan(`handler ${route}`, {
229
+ [ATTR_HTTP_ROUTE]: route,
230
+ [ATTR_OPERATION_ID]: operationId
231
+ }, () => endpoint(internalContext))).catch((e) => {
232
+ if (isAPIError(e)) return {
233
+ response: e,
234
+ status: e.statusCode,
235
+ headers: mergeAPIErrorHeaders(e)
236
+ };
237
+ throw e;
238
+ });
239
+ if (result instanceof Response) return result;
240
+ internalContext.context.returned = result.response;
241
+ internalContext.context.responseHeaders = result.headers ?? void 0;
242
+ const after = await runAfterHooks(internalContext, afterHooks, endpoint, operationId);
243
+ if (after.response !== void 0) result.response = after.response;
244
+ result.headers = after.headers ?? result.headers;
245
+ if (isAPIError(result.response) && shouldPublishLog(internalContext.context.logger.level, "debug")) result.response.stack = result.response.errorStack;
246
+ if (isAPIError(result.response) && !shouldReturnResponse) {
247
+ if (result.headers) Object.defineProperty(result.response, kAPIErrorHeaderSymbol, {
248
+ enumerable: false,
249
+ configurable: true,
250
+ writable: false,
251
+ value: result.headers
252
+ });
253
+ throw result.response;
254
+ }
255
+ return shouldReturnResponse ? toResponse(result.response, {
256
+ headers: result.headers ?? void 0,
257
+ status: result.status
258
+ }) : input.returnHeaders ? input.returnStatus ? {
259
+ headers: result.headers,
260
+ response: result.response,
261
+ status: result.status
262
+ } : {
263
+ headers: result.headers,
264
+ response: result.response
265
+ } : input.returnStatus ? {
266
+ response: result.response,
267
+ status: result.status
268
+ } : result.response;
269
+ }));
270
+ }
271
+ //#endregion
272
+ export { dispatchAuthEndpoint, getOperationId };
@@ -2,6 +2,7 @@ import { OverrideMerge, Prettify as Prettify$1, UnionToIntersection } from "../t
2
2
  import { AdditionalSessionFieldsInput, AdditionalUserFieldsInput } from "../types/models.mjs";
3
3
  import { getIp } from "../utils/get-request-ip.mjs";
4
4
  import { isAPIError } from "../utils/is-api-error.mjs";
5
+ import { DispatchContext, dispatchAuthEndpoint } from "./dispatch.mjs";
5
6
  import { requireOrgRole, requireResourceOwnership } from "./middlewares/authorization.mjs";
6
7
  import { formCsrfMiddleware, originCheck, originCheckMiddleware } from "./middlewares/origin-check.mjs";
7
8
  import { accountInfo, getAccessToken, linkSocialAccount, listUserAccounts, refreshToken, unlinkAccount } from "./routes/account.mjs";
@@ -10,13 +11,13 @@ import { createEmailVerificationToken, sendVerificationEmail, sendVerificationEm
10
11
  import { error } from "./routes/error.mjs";
11
12
  import { ok } from "./routes/ok.mjs";
12
13
  import { requestPasswordReset, requestPasswordResetCallback, resetPassword, verifyPassword } from "./routes/password.mjs";
13
- import { freshSessionMiddleware, getSession, getSessionFromCtx, listSessions, requestOnlySessionMiddleware, revokeOtherSessions, revokeSession, revokeSessions, sensitiveSessionMiddleware, sessionMiddleware } from "./routes/session.mjs";
14
+ import { freshSessionMiddleware, getSession, getSessionFromCtx, isStateful, listSessions, requestOnlySessionMiddleware, revokeOtherSessions, revokeSession, revokeSessions, sensitiveSessionMiddleware, sessionMiddleware } from "./routes/session.mjs";
14
15
  import { signInEmail, signInSocial } from "./routes/sign-in.mjs";
15
16
  import { signOut } from "./routes/sign-out.mjs";
16
17
  import { signUpEmail } from "./routes/sign-up.mjs";
17
18
  import { updateSession } from "./routes/update-session.mjs";
18
19
  import { changeEmail, changePassword, deleteUser, deleteUserCallback, setPassword, updateUser } from "./routes/update-user.mjs";
19
- import { getOAuthState } from "./state/oauth.mjs";
20
+ import { addOAuthServerContext, getOAuthState } from "./state/oauth.mjs";
20
21
  import { getShouldSkipSessionRefresh, setShouldSkipSessionRefresh } from "./state/should-session-refresh.mjs";
21
22
  import { AuthContext, Awaitable, BetterAuthOptions, BetterAuthPlugin } from "@better-auth/core";
22
23
  import * as _better_auth_core_db0 from "@better-auth/core/db";
@@ -24,7 +25,7 @@ import { InternalLogger } from "@better-auth/core/env";
24
25
  import { APIError } from "@better-auth/core/error";
25
26
  import * as _better_auth_core_oauth20 from "@better-auth/core/oauth2";
26
27
  import * as better_call0 from "better-call";
27
- import { AuthEndpoint, AuthMiddleware, createAuthEndpoint, createAuthMiddleware, optionsMiddleware } from "@better-auth/core/api";
28
+ import { AuthEndpoint, AuthMiddleware, NO_STORE_HEADERS, createAuthEndpoint, createAuthMiddleware, optionsMiddleware } from "@better-auth/core/api";
28
29
  import * as zod from "zod";
29
30
  import * as zod_v4_core0 from "zod/v4/core";
30
31
 
@@ -99,6 +100,7 @@ declare function getEndpoints<Option extends BetterAuthOptions>(ctx: Awaitable<A
99
100
  accessToken: zod.ZodOptional<zod.ZodString>;
100
101
  refreshToken: zod.ZodOptional<zod.ZodString>;
101
102
  expiresAt: zod.ZodOptional<zod.ZodNumber>;
103
+ scopes: zod.ZodOptional<zod.ZodArray<zod.ZodString>>;
102
104
  user: zod.ZodOptional<zod.ZodObject<{
103
105
  name: zod.ZodOptional<zod.ZodObject<{
104
106
  firstName: zod.ZodOptional<zod.ZodString>;
@@ -127,6 +129,7 @@ declare function getEndpoints<Option extends BetterAuthOptions>(ctx: Awaitable<A
127
129
  accessToken: zod.ZodOptional<zod.ZodString>;
128
130
  refreshToken: zod.ZodOptional<zod.ZodString>;
129
131
  expiresAt: zod.ZodOptional<zod.ZodNumber>;
132
+ scopes: zod.ZodOptional<zod.ZodArray<zod.ZodString>>;
130
133
  user: zod.ZodOptional<zod.ZodObject<{
131
134
  name: zod.ZodOptional<zod.ZodObject<{
132
135
  firstName: zod.ZodOptional<zod.ZodString>;
@@ -1709,7 +1712,7 @@ declare function getEndpoints<Option extends BetterAuthOptions>(ctx: Awaitable<A
1709
1712
  userId: {
1710
1713
  type: string;
1711
1714
  };
1712
- scopes: {
1715
+ grantedScopes: {
1713
1716
  type: string;
1714
1717
  items: {
1715
1718
  type: string;
@@ -1726,7 +1729,7 @@ declare function getEndpoints<Option extends BetterAuthOptions>(ctx: Awaitable<A
1726
1729
  };
1727
1730
  };
1728
1731
  }, {
1729
- scopes: string[];
1732
+ grantedScopes: string[];
1730
1733
  id: string;
1731
1734
  createdAt: Date;
1732
1735
  updatedAt: Date;
@@ -1866,6 +1869,12 @@ declare function getEndpoints<Option extends BetterAuthOptions>(ctx: Awaitable<A
1866
1869
  type: string;
1867
1870
  format: string;
1868
1871
  };
1872
+ grantedScopes: {
1873
+ type: string;
1874
+ items: {
1875
+ type: string;
1876
+ };
1877
+ };
1869
1878
  };
1870
1879
  };
1871
1880
  };
@@ -1882,7 +1891,7 @@ declare function getEndpoints<Option extends BetterAuthOptions>(ctx: Awaitable<A
1882
1891
  refreshToken: string;
1883
1892
  accessTokenExpiresAt: Date | undefined;
1884
1893
  refreshTokenExpiresAt: Date | null | undefined;
1885
- scope: string | null | undefined;
1894
+ grantedScopes: string[];
1886
1895
  idToken: string | null | undefined;
1887
1896
  providerId: string;
1888
1897
  accountId: string;
@@ -1932,7 +1941,7 @@ declare function getEndpoints<Option extends BetterAuthOptions>(ctx: Awaitable<A
1932
1941
  }, {
1933
1942
  accessToken: string;
1934
1943
  accessTokenExpiresAt: Date | undefined;
1935
- scopes: string[];
1944
+ grantedScopes: string[];
1936
1945
  idToken: string | undefined;
1937
1946
  }>;
1938
1947
  readonly accountInfo: better_call0.StrictEndpoint<"/account-info", {
@@ -2075,6 +2084,7 @@ declare const router: <Option extends BetterAuthOptions>(ctx: AuthContext, optio
2075
2084
  accessToken: zod.ZodOptional<zod.ZodString>;
2076
2085
  refreshToken: zod.ZodOptional<zod.ZodString>;
2077
2086
  expiresAt: zod.ZodOptional<zod.ZodNumber>;
2087
+ scopes: zod.ZodOptional<zod.ZodArray<zod.ZodString>>;
2078
2088
  user: zod.ZodOptional<zod.ZodObject<{
2079
2089
  name: zod.ZodOptional<zod.ZodObject<{
2080
2090
  firstName: zod.ZodOptional<zod.ZodString>;
@@ -2103,6 +2113,7 @@ declare const router: <Option extends BetterAuthOptions>(ctx: AuthContext, optio
2103
2113
  accessToken: zod.ZodOptional<zod.ZodString>;
2104
2114
  refreshToken: zod.ZodOptional<zod.ZodString>;
2105
2115
  expiresAt: zod.ZodOptional<zod.ZodNumber>;
2116
+ scopes: zod.ZodOptional<zod.ZodArray<zod.ZodString>>;
2106
2117
  user: zod.ZodOptional<zod.ZodObject<{
2107
2118
  name: zod.ZodOptional<zod.ZodObject<{
2108
2119
  firstName: zod.ZodOptional<zod.ZodString>;
@@ -3685,7 +3696,7 @@ declare const router: <Option extends BetterAuthOptions>(ctx: AuthContext, optio
3685
3696
  userId: {
3686
3697
  type: string;
3687
3698
  };
3688
- scopes: {
3699
+ grantedScopes: {
3689
3700
  type: string;
3690
3701
  items: {
3691
3702
  type: string;
@@ -3702,7 +3713,7 @@ declare const router: <Option extends BetterAuthOptions>(ctx: AuthContext, optio
3702
3713
  };
3703
3714
  };
3704
3715
  }, {
3705
- scopes: string[];
3716
+ grantedScopes: string[];
3706
3717
  id: string;
3707
3718
  createdAt: Date;
3708
3719
  updatedAt: Date;
@@ -3842,6 +3853,12 @@ declare const router: <Option extends BetterAuthOptions>(ctx: AuthContext, optio
3842
3853
  type: string;
3843
3854
  format: string;
3844
3855
  };
3856
+ grantedScopes: {
3857
+ type: string;
3858
+ items: {
3859
+ type: string;
3860
+ };
3861
+ };
3845
3862
  };
3846
3863
  };
3847
3864
  };
@@ -3858,7 +3875,7 @@ declare const router: <Option extends BetterAuthOptions>(ctx: AuthContext, optio
3858
3875
  refreshToken: string;
3859
3876
  accessTokenExpiresAt: Date | undefined;
3860
3877
  refreshTokenExpiresAt: Date | null | undefined;
3861
- scope: string | null | undefined;
3878
+ grantedScopes: string[];
3862
3879
  idToken: string | null | undefined;
3863
3880
  providerId: string;
3864
3881
  accountId: string;
@@ -3908,7 +3925,7 @@ declare const router: <Option extends BetterAuthOptions>(ctx: AuthContext, optio
3908
3925
  }, {
3909
3926
  accessToken: string;
3910
3927
  accessTokenExpiresAt: Date | undefined;
3911
- scopes: string[];
3928
+ grantedScopes: string[];
3912
3929
  idToken: string | undefined;
3913
3930
  }>;
3914
3931
  readonly accountInfo: better_call0.StrictEndpoint<"/account-info", {
@@ -3972,4 +3989,4 @@ declare const router: <Option extends BetterAuthOptions>(ctx: AuthContext, optio
3972
3989
  } extends infer T_2 ? { [K in keyof T_2 as K extends keyof T_1 ? never : K]: T_2[K] } : never) & T_1> : never : never : never;
3973
3990
  };
3974
3991
  //#endregion
3975
- export { APIError, type AuthEndpoint, type AuthMiddleware, accountInfo, callbackOAuth, changeEmail, changePassword, checkEndpointConflicts, createAuthEndpoint, createAuthMiddleware, createEmailVerificationToken, deleteUser, deleteUserCallback, error, formCsrfMiddleware, freshSessionMiddleware, getAccessToken, getEndpoints, getIp, getOAuthState, getSession, getSessionFromCtx, getShouldSkipSessionRefresh, isAPIError, linkSocialAccount, listSessions, listUserAccounts, ok, optionsMiddleware, originCheck, originCheckMiddleware, refreshToken, requestOnlySessionMiddleware, requestPasswordReset, requestPasswordResetCallback, requireOrgRole, requireResourceOwnership, resetPassword, revokeOtherSessions, revokeSession, revokeSessions, router, sendVerificationEmail, sendVerificationEmailFn, sensitiveSessionMiddleware, sessionMiddleware, setPassword, setShouldSkipSessionRefresh, signInEmail, signInSocial, signOut, signUpEmail, unlinkAccount, updateSession, updateUser, verifyEmail, verifyPassword };
3992
+ export { APIError, type AuthEndpoint, type AuthMiddleware, type DispatchContext, NO_STORE_HEADERS, accountInfo, addOAuthServerContext, callbackOAuth, changeEmail, changePassword, checkEndpointConflicts, createAuthEndpoint, createAuthMiddleware, createEmailVerificationToken, deleteUser, deleteUserCallback, dispatchAuthEndpoint, error, formCsrfMiddleware, freshSessionMiddleware, getAccessToken, getEndpoints, getIp, getOAuthState, getSession, getSessionFromCtx, getShouldSkipSessionRefresh, isAPIError, isStateful, linkSocialAccount, listSessions, listUserAccounts, ok, optionsMiddleware, originCheck, originCheckMiddleware, refreshToken, requestOnlySessionMiddleware, requestPasswordReset, requestPasswordResetCallback, requireOrgRole, requireResourceOwnership, resetPassword, revokeOtherSessions, revokeSession, revokeSessions, router, sendVerificationEmail, sendVerificationEmailFn, sensitiveSessionMiddleware, sessionMiddleware, setPassword, setShouldSkipSessionRefresh, signInEmail, signInSocial, signOut, signUpEmail, unlinkAccount, updateSession, updateUser, verifyEmail, verifyPassword };
@@ -2,10 +2,10 @@ import { isAPIError } from "../utils/is-api-error.mjs";
2
2
  import { requireOrgRole, requireResourceOwnership } from "./middlewares/authorization.mjs";
3
3
  import { formCsrfMiddleware, originCheck, originCheckMiddleware } from "./middlewares/origin-check.mjs";
4
4
  import { getIp } from "../utils/get-request-ip.mjs";
5
- import { onRequestRateLimit, onResponseRateLimit } from "./rate-limiter/index.mjs";
6
- import { getOAuthState } from "./state/oauth.mjs";
5
+ import { onRequestRateLimit } from "./rate-limiter/index.mjs";
6
+ import { addOAuthServerContext, getOAuthState } from "./state/oauth.mjs";
7
7
  import { getShouldSkipSessionRefresh, setShouldSkipSessionRefresh } from "./state/should-session-refresh.mjs";
8
- import { freshSessionMiddleware, getSession, getSessionFromCtx, listSessions, requestOnlySessionMiddleware, revokeOtherSessions, revokeSession, revokeSessions, sensitiveSessionMiddleware, sessionMiddleware } from "./routes/session.mjs";
8
+ import { freshSessionMiddleware, getSession, getSessionFromCtx, isStateful, listSessions, requestOnlySessionMiddleware, revokeOtherSessions, revokeSession, revokeSessions, sensitiveSessionMiddleware, sessionMiddleware } from "./routes/session.mjs";
9
9
  import { accountInfo, getAccessToken, linkSocialAccount, listUserAccounts, refreshToken, unlinkAccount } from "./routes/account.mjs";
10
10
  import { callbackOAuth } from "./routes/callback.mjs";
11
11
  import { createEmailVerificationToken, sendVerificationEmail, sendVerificationEmailFn, verifyEmail } from "./routes/email-verification.mjs";
@@ -17,13 +17,14 @@ import { signOut } from "./routes/sign-out.mjs";
17
17
  import { signUpEmail } from "./routes/sign-up.mjs";
18
18
  import { updateSession } from "./routes/update-session.mjs";
19
19
  import { changeEmail, changePassword, deleteUser, deleteUserCallback, setPassword, updateUser } from "./routes/update-user.mjs";
20
+ import { dispatchAuthEndpoint } from "./dispatch.mjs";
20
21
  import { toAuthEndpoints } from "./to-auth-endpoints.mjs";
21
22
  import { logger } from "@better-auth/core/env";
22
23
  import { APIError } from "@better-auth/core/error";
23
24
  import { ATTR_CONTEXT, ATTR_HOOK_TYPE, ATTR_HTTP_RESPONSE_STATUS_CODE, ATTR_HTTP_ROUTE, withSpan } from "@better-auth/core/instrumentation";
24
25
  import { normalizePathname } from "@better-auth/core/utils/url";
25
26
  import { createRouter } from "better-call";
26
- import { createAuthEndpoint, createAuthMiddleware, optionsMiddleware } from "@better-auth/core/api";
27
+ import { NO_STORE_HEADERS, createAuthEndpoint, createAuthMiddleware, optionsMiddleware } from "@better-auth/core/api";
27
28
  //#region src/api/index.ts
28
29
  function checkEndpointConflicts(options, logger) {
29
30
  const endpointRegistry = /* @__PURE__ */ new Map();
@@ -177,7 +178,6 @@ const router = (ctx, options) => {
177
178
  return currentRequest;
178
179
  },
179
180
  async onResponse(res, req) {
180
- await onResponseRateLimit(req, ctx);
181
181
  for (const plugin of ctx.options.plugins || []) if (plugin.onResponse) {
182
182
  const response = await withSpan(`onResponse ${plugin.id}`, {
183
183
  [ATTR_HOOK_TYPE]: "onResponse",
@@ -213,4 +213,4 @@ const router = (ctx, options) => {
213
213
  });
214
214
  };
215
215
  //#endregion
216
- export { APIError, accountInfo, callbackOAuth, changeEmail, changePassword, checkEndpointConflicts, createAuthEndpoint, createAuthMiddleware, createEmailVerificationToken, deleteUser, deleteUserCallback, error, formCsrfMiddleware, freshSessionMiddleware, getAccessToken, getEndpoints, getIp, getOAuthState, getSession, getSessionFromCtx, getShouldSkipSessionRefresh, isAPIError, linkSocialAccount, listSessions, listUserAccounts, ok, optionsMiddleware, originCheck, originCheckMiddleware, refreshToken, requestOnlySessionMiddleware, requestPasswordReset, requestPasswordResetCallback, requireOrgRole, requireResourceOwnership, resetPassword, revokeOtherSessions, revokeSession, revokeSessions, router, sendVerificationEmail, sendVerificationEmailFn, sensitiveSessionMiddleware, sessionMiddleware, setPassword, setShouldSkipSessionRefresh, signInEmail, signInSocial, signOut, signUpEmail, unlinkAccount, updateSession, updateUser, verifyEmail, verifyPassword };
216
+ export { APIError, NO_STORE_HEADERS, accountInfo, addOAuthServerContext, callbackOAuth, changeEmail, changePassword, checkEndpointConflicts, createAuthEndpoint, createAuthMiddleware, createEmailVerificationToken, deleteUser, deleteUserCallback, dispatchAuthEndpoint, error, formCsrfMiddleware, freshSessionMiddleware, getAccessToken, getEndpoints, getIp, getOAuthState, getSession, getSessionFromCtx, getShouldSkipSessionRefresh, isAPIError, isStateful, linkSocialAccount, listSessions, listUserAccounts, ok, optionsMiddleware, originCheck, originCheckMiddleware, refreshToken, requestOnlySessionMiddleware, requestPasswordReset, requestPasswordResetCallback, requireOrgRole, requireResourceOwnership, resetPassword, revokeOtherSessions, revokeSession, revokeSessions, router, sendVerificationEmail, sendVerificationEmailFn, sensitiveSessionMiddleware, sessionMiddleware, setPassword, setShouldSkipSessionRefresh, signInEmail, signInSocial, signOut, signUpEmail, unlinkAccount, updateSession, updateUser, verifyEmail, verifyPassword };
@@ -23,7 +23,10 @@ function shouldSkipOriginCheck(ctx) {
23
23
  if (Array.isArray(skipOriginCheck) && ctx.request) try {
24
24
  const basePath = new URL(ctx.context.baseURL).pathname;
25
25
  const currentPath = normalizePathname(ctx.request.url, basePath);
26
- return skipOriginCheck.some((skipPath) => currentPath.startsWith(skipPath));
26
+ return skipOriginCheck.some((skipPath) => {
27
+ const normalizedSkipPath = skipPath.replace(/\/+$/, "");
28
+ return currentPath === normalizedSkipPath || currentPath.startsWith(`${normalizedSkipPath}/`);
29
+ });
27
30
  } catch {}
28
31
  return false;
29
32
  }
@@ -47,6 +50,7 @@ const originCheckMiddleware = createAuthMiddleware(async (ctx) => {
47
50
  const newUserCallbackURL = body?.newUserCallbackURL;
48
51
  const validateURL = (url, label) => {
49
52
  if (!url) return;
53
+ if (typeof url !== "string") throw APIError.fromStatus("BAD_REQUEST", { message: `Invalid ${label}: expected a string` });
50
54
  if (!ctx.context.isTrustedOrigin(url, { allowRelativePaths: label !== "origin" })) {
51
55
  ctx.context.logger.error(`Invalid ${label}: ${url}`);
52
56
  ctx.context.logger.info(`If it's a valid URL, please add ${url} to trustedOrigins in your auth config\n`, `Current list of trustedOrigins: ${ctx.context.trustedOrigins}`);
@@ -141,6 +145,7 @@ async function validateFormCsrf(ctx) {
141
145
  }
142
146
  return await validateOrigin(ctx, true);
143
147
  }
148
+ if (headers.get("origin") || headers.get("referer")) return await validateOrigin(ctx, true);
144
149
  }
145
150
  //#endregion
146
151
  export { formCsrfMiddleware, originCheck, originCheckMiddleware };