@masheev/better-auth 0.0.0-stage → 1.7.5

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 (465) hide show
  1. package/LICENSE.md +20 -0
  2. package/README.md +31 -2
  3. package/TYPE-PATCH-NOTICE.md +9 -0
  4. package/TYPE-PATCH-PROVENANCE.json +267 -0
  5. package/dist/_virtual/_rolldown/runtime.mjs +27 -0
  6. package/dist/adapters/drizzle-adapter/index.d.mts +1 -0
  7. package/dist/adapters/drizzle-adapter/index.mjs +2 -0
  8. package/dist/adapters/index.d.mts +26 -0
  9. package/dist/adapters/index.mjs +9 -0
  10. package/dist/adapters/kysely-adapter/index.d.mts +1 -0
  11. package/dist/adapters/kysely-adapter/index.mjs +2 -0
  12. package/dist/adapters/memory-adapter/index.d.mts +1 -0
  13. package/dist/adapters/memory-adapter/index.mjs +2 -0
  14. package/dist/adapters/mongodb-adapter/index.d.mts +1 -0
  15. package/dist/adapters/mongodb-adapter/index.mjs +2 -0
  16. package/dist/adapters/prisma-adapter/index.d.mts +1 -0
  17. package/dist/adapters/prisma-adapter/index.mjs +2 -0
  18. package/dist/api/dispatch.d.mts +34 -0
  19. package/dist/api/dispatch.mjs +275 -0
  20. package/dist/api/index.d.mts +4053 -0
  21. package/dist/api/index.mjs +220 -0
  22. package/dist/api/middlewares/authorization.d.mts +69 -0
  23. package/dist/api/middlewares/authorization.mjs +78 -0
  24. package/dist/api/middlewares/index.d.mts +2 -0
  25. package/dist/api/middlewares/origin-check.d.mts +17 -0
  26. package/dist/api/middlewares/origin-check.mjs +155 -0
  27. package/dist/api/rate-limiter/index.mjs +318 -0
  28. package/dist/api/routes/account.d.mts +413 -0
  29. package/dist/api/routes/account.mjs +619 -0
  30. package/dist/api/routes/callback.d.mts +32 -0
  31. package/dist/api/routes/callback.mjs +261 -0
  32. package/dist/api/routes/email-verification.d.mts +160 -0
  33. package/dist/api/routes/email-verification.mjs +324 -0
  34. package/dist/api/routes/error.d.mts +27 -0
  35. package/dist/api/routes/error.mjs +387 -0
  36. package/dist/api/routes/index.d.mts +12 -0
  37. package/dist/api/routes/ok.d.mts +35 -0
  38. package/dist/api/routes/ok.mjs +27 -0
  39. package/dist/api/routes/password.d.mts +182 -0
  40. package/dist/api/routes/password.mjs +206 -0
  41. package/dist/api/routes/session.d.mts +450 -0
  42. package/dist/api/routes/session.mjs +481 -0
  43. package/dist/api/routes/sign-in.d.mts +186 -0
  44. package/dist/api/routes/sign-in.mjs +368 -0
  45. package/dist/api/routes/sign-out.d.mts +51 -0
  46. package/dist/api/routes/sign-out.mjs +96 -0
  47. package/dist/api/routes/sign-up.d.mts +159 -0
  48. package/dist/api/routes/sign-up.mjs +275 -0
  49. package/dist/api/routes/update-session.d.mts +74 -0
  50. package/dist/api/routes/update-session.mjs +57 -0
  51. package/dist/api/routes/update-user.d.mts +428 -0
  52. package/dist/api/routes/update-user.mjs +522 -0
  53. package/dist/api/state/oauth.d.mts +53 -0
  54. package/dist/api/state/oauth.mjs +38 -0
  55. package/dist/api/state/should-session-refresh.d.mts +12 -0
  56. package/dist/api/state/should-session-refresh.mjs +13 -0
  57. package/dist/api/to-auth-endpoints.mjs +60 -0
  58. package/dist/auth/base.mjs +66 -0
  59. package/dist/auth/full.d.mts +28 -0
  60. package/dist/auth/full.mjs +29 -0
  61. package/dist/auth/minimal.d.mts +10 -0
  62. package/dist/auth/minimal.mjs +11 -0
  63. package/dist/auth/trusted-origins.mjs +106 -0
  64. package/dist/client/broadcast-channel.d.mts +19 -0
  65. package/dist/client/broadcast-channel.mjs +44 -0
  66. package/dist/client/config.d.mts +90 -0
  67. package/dist/client/config.mjs +113 -0
  68. package/dist/client/equality.d.mts +19 -0
  69. package/dist/client/equality.mjs +42 -0
  70. package/dist/client/fetch-plugins.mjs +17 -0
  71. package/dist/client/focus-manager.d.mts +10 -0
  72. package/dist/client/focus-manager.mjs +30 -0
  73. package/dist/client/index.d.mts +35 -0
  74. package/dist/client/index.mjs +22 -0
  75. package/dist/client/lynx/index.d.mts +43 -0
  76. package/dist/client/lynx/index.mjs +22 -0
  77. package/dist/client/lynx/lynx-store.d.mts +46 -0
  78. package/dist/client/lynx/lynx-store.mjs +44 -0
  79. package/dist/client/online-manager.d.mts +11 -0
  80. package/dist/client/online-manager.mjs +33 -0
  81. package/dist/client/parser.d.mts +10 -0
  82. package/dist/client/parser.mjs +70 -0
  83. package/dist/client/path-to-object.d.mts +113 -0
  84. package/dist/client/plugins/index.d.mts +44 -0
  85. package/dist/client/plugins/index.mjs +30 -0
  86. package/dist/client/plugins/infer-plugin.d.mts +16 -0
  87. package/dist/client/plugins/infer-plugin.mjs +11 -0
  88. package/dist/client/proxy.mjs +78 -0
  89. package/dist/client/query.d.mts +23 -0
  90. package/dist/client/query.mjs +124 -0
  91. package/dist/client/react/index.d.mts +44 -0
  92. package/dist/client/react/index.mjs +22 -0
  93. package/dist/client/react/react-store.d.mts +46 -0
  94. package/dist/client/react/react-store.mjs +44 -0
  95. package/dist/client/session-atom.d.mts +11 -0
  96. package/dist/client/session-atom.mjs +178 -0
  97. package/dist/client/session-refresh.d.mts +20 -0
  98. package/dist/client/session-refresh.mjs +131 -0
  99. package/dist/client/solid/index.d.mts +44 -0
  100. package/dist/client/solid/index.mjs +22 -0
  101. package/dist/client/solid/solid-store.mjs +21 -0
  102. package/dist/client/svelte/index.d.mts +44 -0
  103. package/dist/client/svelte/index.mjs +18 -0
  104. package/dist/client/types.d.mts +51 -0
  105. package/dist/client/vanilla.d.mts +42 -0
  106. package/dist/client/vanilla.mjs +18 -0
  107. package/dist/client/vue/index.d.mts +67 -0
  108. package/dist/client/vue/index.mjs +54 -0
  109. package/dist/client/vue/vue-store.mjs +23 -0
  110. package/dist/context/create-context.mjs +235 -0
  111. package/dist/context/helpers.mjs +158 -0
  112. package/dist/context/init-minimal.mjs +17 -0
  113. package/dist/context/init.mjs +19 -0
  114. package/dist/context/secret-utils.mjs +53 -0
  115. package/dist/context/store-capabilities.mjs +12 -0
  116. package/dist/cookies/cache.mjs +33 -0
  117. package/dist/cookies/cookie-utils.d.mts +72 -0
  118. package/dist/cookies/cookie-utils.mjs +203 -0
  119. package/dist/cookies/index.d.mts +124 -0
  120. package/dist/cookies/index.mjs +350 -0
  121. package/dist/cookies/jwt.mjs +44 -0
  122. package/dist/cookies/session-store.d.mts +32 -0
  123. package/dist/cookies/session-store.mjs +183 -0
  124. package/dist/crypto/buffer.d.mts +7 -0
  125. package/dist/crypto/buffer.mjs +16 -0
  126. package/dist/crypto/index.d.mts +32 -0
  127. package/dist/crypto/index.mjs +69 -0
  128. package/dist/crypto/jwt.d.mts +9 -0
  129. package/dist/crypto/jwt.mjs +141 -0
  130. package/dist/crypto/password.d.mts +13 -0
  131. package/dist/crypto/password.mjs +14 -0
  132. package/dist/crypto/random.d.mts +4 -0
  133. package/dist/crypto/random.mjs +5 -0
  134. package/dist/db/adapter-base.d.mts +7 -0
  135. package/dist/db/adapter-base.mjs +25 -0
  136. package/dist/db/adapter-kysely.d.mts +7 -0
  137. package/dist/db/adapter-kysely.mjs +17 -0
  138. package/dist/db/field-converter.d.mts +7 -0
  139. package/dist/db/field-converter.mjs +19 -0
  140. package/dist/db/field.d.mts +41 -0
  141. package/dist/db/get-migration.d.mts +56 -0
  142. package/dist/db/get-migration.mjs +685 -0
  143. package/dist/db/get-schema.d.mts +13 -0
  144. package/dist/db/get-schema.mjs +39 -0
  145. package/dist/db/index.d.mts +10 -0
  146. package/dist/db/index.mjs +35 -0
  147. package/dist/db/internal-adapter.d.mts +14 -0
  148. package/dist/db/internal-adapter.mjs +951 -0
  149. package/dist/db/revoke-unproven-account-access.d.mts +21 -0
  150. package/dist/db/revoke-unproven-account-access.mjs +58 -0
  151. package/dist/db/schema.d.mts +62 -0
  152. package/dist/db/schema.mjs +161 -0
  153. package/dist/db/to-zod.d.mts +35 -0
  154. package/dist/db/to-zod.mjs +23 -0
  155. package/dist/db/verification-token-storage.mjs +25 -0
  156. package/dist/db/with-hooks.d.mts +37 -0
  157. package/dist/db/with-hooks.mjs +255 -0
  158. package/dist/index.d.mts +30 -0
  159. package/dist/index.mjs +17 -0
  160. package/dist/integrations/cookie-plugin-guard.mjs +18 -0
  161. package/dist/integrations/next-js.d.mts +29 -0
  162. package/dist/integrations/next-js.mjs +105 -0
  163. package/dist/integrations/node.d.mts +11 -0
  164. package/dist/integrations/node.mjs +13 -0
  165. package/dist/integrations/solid-start.d.mts +22 -0
  166. package/dist/integrations/solid-start.mjs +15 -0
  167. package/dist/integrations/svelte-kit.d.mts +38 -0
  168. package/dist/integrations/svelte-kit.mjs +57 -0
  169. package/dist/integrations/tanstack-start-solid.d.mts +33 -0
  170. package/dist/integrations/tanstack-start-solid.mjs +57 -0
  171. package/dist/integrations/tanstack-start.d.mts +33 -0
  172. package/dist/integrations/tanstack-start.mjs +57 -0
  173. package/dist/oauth2/account-key.mjs +43 -0
  174. package/dist/oauth2/errors.mjs +49 -0
  175. package/dist/oauth2/index.d.mts +5 -0
  176. package/dist/oauth2/index.mjs +5 -0
  177. package/dist/oauth2/link-account.d.mts +96 -0
  178. package/dist/oauth2/link-account.mjs +329 -0
  179. package/dist/oauth2/state.d.mts +54 -0
  180. package/dist/oauth2/state.mjs +67 -0
  181. package/dist/oauth2/utils.d.mts +11 -0
  182. package/dist/oauth2/utils.mjs +33 -0
  183. package/dist/package.mjs +4 -0
  184. package/dist/plugins/access/access.d.mts +17 -0
  185. package/dist/plugins/access/access.mjs +78 -0
  186. package/dist/plugins/access/index.d.mts +3 -0
  187. package/dist/plugins/access/index.mjs +2 -0
  188. package/dist/plugins/access/types.d.mts +24 -0
  189. package/dist/plugins/additional-fields/client.d.mts +100 -0
  190. package/dist/plugins/additional-fields/client.mjs +11 -0
  191. package/dist/plugins/admin/access/index.d.mts +2 -0
  192. package/dist/plugins/admin/access/index.mjs +2 -0
  193. package/dist/plugins/admin/access/statement.d.mts +51 -0
  194. package/dist/plugins/admin/access/statement.mjs +52 -0
  195. package/dist/plugins/admin/admin.d.mts +911 -0
  196. package/dist/plugins/admin/admin.mjs +89 -0
  197. package/dist/plugins/admin/client.d.mts +81 -0
  198. package/dist/plugins/admin/client.mjs +39 -0
  199. package/dist/plugins/admin/error-codes.d.mts +30 -0
  200. package/dist/plugins/admin/error-codes.mjs +29 -0
  201. package/dist/plugins/admin/has-permission.mjs +12 -0
  202. package/dist/plugins/admin/index.d.mts +3 -0
  203. package/dist/plugins/admin/index.mjs +2 -0
  204. package/dist/plugins/admin/routes.mjs +919 -0
  205. package/dist/plugins/admin/schema.d.mts +40 -0
  206. package/dist/plugins/admin/schema.mjs +33 -0
  207. package/dist/plugins/admin/types.d.mts +88 -0
  208. package/dist/plugins/anonymous/client.d.mts +32 -0
  209. package/dist/plugins/anonymous/client.mjs +21 -0
  210. package/dist/plugins/anonymous/error-codes.d.mts +15 -0
  211. package/dist/plugins/anonymous/error-codes.mjs +14 -0
  212. package/dist/plugins/anonymous/index.d.mts +175 -0
  213. package/dist/plugins/anonymous/index.mjs +219 -0
  214. package/dist/plugins/anonymous/schema.d.mts +15 -0
  215. package/dist/plugins/anonymous/schema.mjs +9 -0
  216. package/dist/plugins/anonymous/types.d.mts +65 -0
  217. package/dist/plugins/bearer/index.d.mts +45 -0
  218. package/dist/plugins/bearer/index.mjs +74 -0
  219. package/dist/plugins/captcha/constants.d.mts +9 -0
  220. package/dist/plugins/captcha/constants.mjs +27 -0
  221. package/dist/plugins/captcha/error-codes.mjs +13 -0
  222. package/dist/plugins/captcha/index.d.mts +27 -0
  223. package/dist/plugins/captcha/index.mjs +79 -0
  224. package/dist/plugins/captcha/types.d.mts +52 -0
  225. package/dist/plugins/captcha/utils.mjs +9 -0
  226. package/dist/plugins/captcha/verify-handlers/captchafox.mjs +27 -0
  227. package/dist/plugins/captcha/verify-handlers/cloudflare-turnstile.mjs +47 -0
  228. package/dist/plugins/captcha/verify-handlers/google-recaptcha.mjs +32 -0
  229. package/dist/plugins/captcha/verify-handlers/h-captcha.mjs +27 -0
  230. package/dist/plugins/custom-session/client.d.mts +17 -0
  231. package/dist/plugins/custom-session/client.mjs +7 -0
  232. package/dist/plugins/custom-session/index.d.mts +73 -0
  233. package/dist/plugins/custom-session/index.mjs +65 -0
  234. package/dist/plugins/device-authorization/client.d.mts +17 -0
  235. package/dist/plugins/device-authorization/client.mjs +18 -0
  236. package/dist/plugins/device-authorization/error-codes.mjs +19 -0
  237. package/dist/plugins/device-authorization/index.d.mts +558 -0
  238. package/dist/plugins/device-authorization/index.mjs +87 -0
  239. package/dist/plugins/device-authorization/routes.d.mts +32 -0
  240. package/dist/plugins/device-authorization/routes.mjs +725 -0
  241. package/dist/plugins/device-authorization/schema.d.mts +18 -0
  242. package/dist/plugins/device-authorization/schema.mjs +63 -0
  243. package/dist/plugins/email-otp/client.d.mts +21 -0
  244. package/dist/plugins/email-otp/client.mjs +17 -0
  245. package/dist/plugins/email-otp/error-codes.d.mts +10 -0
  246. package/dist/plugins/email-otp/error-codes.mjs +9 -0
  247. package/dist/plugins/email-otp/index.d.mts +551 -0
  248. package/dist/plugins/email-otp/index.mjs +145 -0
  249. package/dist/plugins/email-otp/otp-token.mjs +55 -0
  250. package/dist/plugins/email-otp/routes.mjs +784 -0
  251. package/dist/plugins/email-otp/types.d.mts +109 -0
  252. package/dist/plugins/email-otp/utils.mjs +17 -0
  253. package/dist/plugins/generic-oauth/error-codes.mjs +8 -0
  254. package/dist/plugins/generic-oauth/index.d.mts +52 -0
  255. package/dist/plugins/generic-oauth/index.mjs +279 -0
  256. package/dist/plugins/generic-oauth/providers/auth0.d.mts +36 -0
  257. package/dist/plugins/generic-oauth/providers/auth0.mjs +49 -0
  258. package/dist/plugins/generic-oauth/providers/gumroad.d.mts +31 -0
  259. package/dist/plugins/generic-oauth/providers/gumroad.mjs +62 -0
  260. package/dist/plugins/generic-oauth/providers/hubspot.d.mts +36 -0
  261. package/dist/plugins/generic-oauth/providers/hubspot.mjs +62 -0
  262. package/dist/plugins/generic-oauth/providers/index.d.mts +10 -0
  263. package/dist/plugins/generic-oauth/providers/keycloak.d.mts +36 -0
  264. package/dist/plugins/generic-oauth/providers/keycloak.mjs +47 -0
  265. package/dist/plugins/generic-oauth/providers/line.d.mts +54 -0
  266. package/dist/plugins/generic-oauth/providers/line.mjs +93 -0
  267. package/dist/plugins/generic-oauth/providers/microsoft-entra-id.d.mts +39 -0
  268. package/dist/plugins/generic-oauth/providers/microsoft-entra-id.mjs +104 -0
  269. package/dist/plugins/generic-oauth/providers/okta.d.mts +36 -0
  270. package/dist/plugins/generic-oauth/providers/okta.mjs +47 -0
  271. package/dist/plugins/generic-oauth/providers/patreon.d.mts +29 -0
  272. package/dist/plugins/generic-oauth/providers/patreon.mjs +61 -0
  273. package/dist/plugins/generic-oauth/providers/slack.d.mts +29 -0
  274. package/dist/plugins/generic-oauth/providers/slack.mjs +63 -0
  275. package/dist/plugins/generic-oauth/providers/yandex.d.mts +29 -0
  276. package/dist/plugins/generic-oauth/providers/yandex.mjs +67 -0
  277. package/dist/plugins/generic-oauth/types.d.mts +268 -0
  278. package/dist/plugins/haveibeenpwned/index.d.mts +63 -0
  279. package/dist/plugins/haveibeenpwned/index.mjs +81 -0
  280. package/dist/plugins/index.d.mts +69 -0
  281. package/dist/plugins/index.mjs +49 -0
  282. package/dist/plugins/jwt/adapter.mjs +68 -0
  283. package/dist/plugins/jwt/client.d.mts +41 -0
  284. package/dist/plugins/jwt/client.mjs +19 -0
  285. package/dist/plugins/jwt/cookie-cache.mjs +77 -0
  286. package/dist/plugins/jwt/index.d.mts +246 -0
  287. package/dist/plugins/jwt/index.mjs +214 -0
  288. package/dist/plugins/jwt/schema.d.mts +33 -0
  289. package/dist/plugins/jwt/schema.mjs +29 -0
  290. package/dist/plugins/jwt/sign.d.mts +128 -0
  291. package/dist/plugins/jwt/sign.mjs +130 -0
  292. package/dist/plugins/jwt/types.d.mts +256 -0
  293. package/dist/plugins/jwt/utils.d.mts +41 -0
  294. package/dist/plugins/jwt/utils.mjs +64 -0
  295. package/dist/plugins/jwt/verify.d.mts +11 -0
  296. package/dist/plugins/jwt/verify.mjs +45 -0
  297. package/dist/plugins/last-login-method/client.d.mts +48 -0
  298. package/dist/plugins/last-login-method/client.mjs +48 -0
  299. package/dist/plugins/last-login-method/index.d.mts +127 -0
  300. package/dist/plugins/last-login-method/index.mjs +98 -0
  301. package/dist/plugins/magic-link/client.d.mts +10 -0
  302. package/dist/plugins/magic-link/client.mjs +11 -0
  303. package/dist/plugins/magic-link/index.d.mts +213 -0
  304. package/dist/plugins/magic-link/index.mjs +208 -0
  305. package/dist/plugins/magic-link/utils.mjs +9 -0
  306. package/dist/plugins/multi-session/client.d.mts +19 -0
  307. package/dist/plugins/multi-session/client.mjs +19 -0
  308. package/dist/plugins/multi-session/error-codes.d.mts +8 -0
  309. package/dist/plugins/multi-session/error-codes.mjs +5 -0
  310. package/dist/plugins/multi-session/index.d.mts +212 -0
  311. package/dist/plugins/multi-session/index.mjs +217 -0
  312. package/dist/plugins/oauth-popup/client.d.mts +82 -0
  313. package/dist/plugins/oauth-popup/client.mjs +203 -0
  314. package/dist/plugins/oauth-popup/constants.d.mts +11 -0
  315. package/dist/plugins/oauth-popup/constants.mjs +11 -0
  316. package/dist/plugins/oauth-popup/error-codes.d.mts +11 -0
  317. package/dist/plugins/oauth-popup/error-codes.mjs +10 -0
  318. package/dist/plugins/oauth-popup/index.d.mts +67 -0
  319. package/dist/plugins/oauth-popup/index.mjs +232 -0
  320. package/dist/plugins/oauth-popup/types.d.mts +30 -0
  321. package/dist/plugins/oauth-proxy/index.d.mts +130 -0
  322. package/dist/plugins/oauth-proxy/index.mjs +407 -0
  323. package/dist/plugins/oauth-proxy/utils.mjs +55 -0
  324. package/dist/plugins/one-tap/client.d.mts +174 -0
  325. package/dist/plugins/one-tap/client.mjs +208 -0
  326. package/dist/plugins/one-tap/index.d.mts +82 -0
  327. package/dist/plugins/one-tap/index.mjs +100 -0
  328. package/dist/plugins/one-time-token/client.d.mts +10 -0
  329. package/dist/plugins/one-time-token/client.mjs +11 -0
  330. package/dist/plugins/one-time-token/index.d.mts +132 -0
  331. package/dist/plugins/one-time-token/index.mjs +107 -0
  332. package/dist/plugins/one-time-token/utils.mjs +9 -0
  333. package/dist/plugins/open-api/generator.d.mts +126 -0
  334. package/dist/plugins/open-api/generator.mjs +557 -0
  335. package/dist/plugins/open-api/index.d.mts +97 -0
  336. package/dist/plugins/open-api/index.mjs +65 -0
  337. package/dist/plugins/open-api/logo.mjs +13 -0
  338. package/dist/plugins/organization/access/index.d.mts +2 -0
  339. package/dist/plugins/organization/access/index.mjs +2 -0
  340. package/dist/plugins/organization/access/statement.d.mts +113 -0
  341. package/dist/plugins/organization/access/statement.mjs +77 -0
  342. package/dist/plugins/organization/adapter.d.mts +815 -0
  343. package/dist/plugins/organization/adapter.mjs +813 -0
  344. package/dist/plugins/organization/call.mjs +15 -0
  345. package/dist/plugins/organization/client.d.mts +375 -0
  346. package/dist/plugins/organization/client.mjs +104 -0
  347. package/dist/plugins/organization/error-codes.d.mts +66 -0
  348. package/dist/plugins/organization/error-codes.mjs +65 -0
  349. package/dist/plugins/organization/has-permission.d.mts +17 -0
  350. package/dist/plugins/organization/has-permission.mjs +34 -0
  351. package/dist/plugins/organization/index.d.mts +6 -0
  352. package/dist/plugins/organization/index.mjs +4 -0
  353. package/dist/plugins/organization/organization.d.mts +420 -0
  354. package/dist/plugins/organization/organization.mjs +886 -0
  355. package/dist/plugins/organization/permission.d.mts +15 -0
  356. package/dist/plugins/organization/permission.mjs +14 -0
  357. package/dist/plugins/organization/routes/crud-access-control.d.mts +511 -0
  358. package/dist/plugins/organization/routes/crud-access-control.mjs +674 -0
  359. package/dist/plugins/organization/routes/crud-invites.d.mts +1154 -0
  360. package/dist/plugins/organization/routes/crud-invites.mjs +602 -0
  361. package/dist/plugins/organization/routes/crud-members.d.mts +1057 -0
  362. package/dist/plugins/organization/routes/crud-members.mjs +518 -0
  363. package/dist/plugins/organization/routes/crud-org.d.mts +918 -0
  364. package/dist/plugins/organization/routes/crud-org.mjs +455 -0
  365. package/dist/plugins/organization/routes/crud-team.d.mts +1238 -0
  366. package/dist/plugins/organization/routes/crud-team.mjs +766 -0
  367. package/dist/plugins/organization/schema.d.mts +390 -0
  368. package/dist/plugins/organization/schema.mjs +65 -0
  369. package/dist/plugins/organization/types.d.mts +691 -0
  370. package/dist/plugins/phone-number/client.d.mts +31 -0
  371. package/dist/plugins/phone-number/client.mjs +19 -0
  372. package/dist/plugins/phone-number/error-codes.d.mts +19 -0
  373. package/dist/plugins/phone-number/error-codes.mjs +18 -0
  374. package/dist/plugins/phone-number/index.d.mts +360 -0
  375. package/dist/plugins/phone-number/index.mjs +57 -0
  376. package/dist/plugins/phone-number/routes.mjs +529 -0
  377. package/dist/plugins/phone-number/schema.d.mts +22 -0
  378. package/dist/plugins/phone-number/schema.mjs +18 -0
  379. package/dist/plugins/phone-number/types.d.mts +116 -0
  380. package/dist/plugins/siwe/client.d.mts +14 -0
  381. package/dist/plugins/siwe/client.mjs +15 -0
  382. package/dist/plugins/siwe/index.d.mts +62 -0
  383. package/dist/plugins/siwe/index.mjs +272 -0
  384. package/dist/plugins/siwe/parse-message.mjs +60 -0
  385. package/dist/plugins/siwe/schema.d.mts +35 -0
  386. package/dist/plugins/siwe/schema.mjs +30 -0
  387. package/dist/plugins/siwe/types.d.mts +43 -0
  388. package/dist/plugins/test-utils/auth-helpers.mjs +33 -0
  389. package/dist/plugins/test-utils/cookie-builder.mjs +55 -0
  390. package/dist/plugins/test-utils/db-helpers.mjs +65 -0
  391. package/dist/plugins/test-utils/factories.mjs +38 -0
  392. package/dist/plugins/test-utils/index.d.mts +73 -0
  393. package/dist/plugins/test-utils/index.mjs +97 -0
  394. package/dist/plugins/test-utils/otp-sink.mjs +21 -0
  395. package/dist/plugins/test-utils/types.d.mts +51 -0
  396. package/dist/plugins/two-factor/backup-codes/index.d.mts +291 -0
  397. package/dist/plugins/two-factor/backup-codes/index.mjs +341 -0
  398. package/dist/plugins/two-factor/client.d.mts +76 -0
  399. package/dist/plugins/two-factor/client.mjs +41 -0
  400. package/dist/plugins/two-factor/constant.mjs +6 -0
  401. package/dist/plugins/two-factor/error-code.d.mts +20 -0
  402. package/dist/plugins/two-factor/error-code.mjs +19 -0
  403. package/dist/plugins/two-factor/index.d.mts +720 -0
  404. package/dist/plugins/two-factor/index.mjs +349 -0
  405. package/dist/plugins/two-factor/otp/index.d.mts +216 -0
  406. package/dist/plugins/two-factor/otp/index.mjs +252 -0
  407. package/dist/plugins/two-factor/schema.d.mts +59 -0
  408. package/dist/plugins/two-factor/schema.mjs +53 -0
  409. package/dist/plugins/two-factor/totp/index.d.mts +219 -0
  410. package/dist/plugins/two-factor/totp/index.mjs +230 -0
  411. package/dist/plugins/two-factor/types.d.mts +111 -0
  412. package/dist/plugins/two-factor/utils.mjs +9 -0
  413. package/dist/plugins/two-factor/verify-two-factor.mjs +205 -0
  414. package/dist/plugins/username/client.d.mts +38 -0
  415. package/dist/plugins/username/client.mjs +17 -0
  416. package/dist/plugins/username/error-codes.d.mts +16 -0
  417. package/dist/plugins/username/error-codes.mjs +15 -0
  418. package/dist/plugins/username/index.d.mts +326 -0
  419. package/dist/plugins/username/index.mjs +312 -0
  420. package/dist/plugins/username/schema.d.mts +50 -0
  421. package/dist/plugins/username/schema.mjs +25 -0
  422. package/dist/social-providers/index.d.mts +1 -0
  423. package/dist/social-providers/index.mjs +2 -0
  424. package/dist/state.d.mts +48 -0
  425. package/dist/state.mjs +149 -0
  426. package/dist/test-utils/headers.d.mts +8 -0
  427. package/dist/test-utils/headers.mjs +17 -0
  428. package/dist/test-utils/http-test-instance.d.mts +413 -0
  429. package/dist/test-utils/http-test-instance.mjs +107 -0
  430. package/dist/test-utils/index.d.mts +4 -0
  431. package/dist/test-utils/index.mjs +4 -0
  432. package/dist/test-utils/test-instance.d.mts +56 -0
  433. package/dist/test-utils/test-instance.mjs +242 -0
  434. package/dist/types/adapter.d.mts +2 -0
  435. package/dist/types/api.d.mts +28 -0
  436. package/dist/types/auth.d.mts +32 -0
  437. package/dist/types/helper.d.mts +26 -0
  438. package/dist/types/index.d.mts +10 -0
  439. package/dist/types/index.mjs +1 -0
  440. package/dist/types/models.d.mts +10 -0
  441. package/dist/types/plugins.d.mts +19 -0
  442. package/dist/utils/boolean.mjs +6 -0
  443. package/dist/utils/constants.mjs +4 -0
  444. package/dist/utils/date.mjs +6 -0
  445. package/dist/utils/hashing.mjs +18 -0
  446. package/dist/utils/hide-metadata.d.mts +6 -0
  447. package/dist/utils/hide-metadata.mjs +4 -0
  448. package/dist/utils/index.d.mts +4 -0
  449. package/dist/utils/is-api-error.d.mts +2 -0
  450. package/dist/utils/is-api-error.mjs +2 -0
  451. package/dist/utils/is-atom.mjs +6 -0
  452. package/dist/utils/is-promise.mjs +6 -0
  453. package/dist/utils/middleware-response.mjs +7 -0
  454. package/dist/utils/password.mjs +32 -0
  455. package/dist/utils/plugin-helper.mjs +14 -0
  456. package/dist/utils/request.mjs +23 -0
  457. package/dist/utils/shim.mjs +22 -0
  458. package/dist/utils/time.d.mts +48 -0
  459. package/dist/utils/time.mjs +98 -0
  460. package/dist/utils/url.d.mts +78 -0
  461. package/dist/utils/url.mjs +238 -0
  462. package/dist/utils/validate-user-info.mjs +44 -0
  463. package/dist/utils/wildcard.mjs +106 -0
  464. package/dist/version.mjs +5 -0
  465. package/package.json +595 -3
@@ -0,0 +1,63 @@
1
+ import { betterFetch } from "@better-fetch/fetch";
2
+ //#region src/plugins/generic-oauth/providers/slack.ts
3
+ /**
4
+ * Slack OAuth provider helper
5
+ *
6
+ * @example
7
+ * ```ts
8
+ * import { genericOAuth, slack } from "better-auth/plugins/generic-oauth";
9
+ *
10
+ * export const auth = betterAuth({
11
+ * plugins: [
12
+ * genericOAuth({
13
+ * config: [
14
+ * slack({
15
+ * clientId: process.env.SLACK_CLIENT_ID,
16
+ * clientSecret: process.env.SLACK_CLIENT_SECRET,
17
+ * }),
18
+ * ],
19
+ * }),
20
+ * ],
21
+ * });
22
+ * ```
23
+ */
24
+ function slack(options) {
25
+ const defaultScopes = [
26
+ "openid",
27
+ "profile",
28
+ "email"
29
+ ];
30
+ const getUserInfo = async (tokens) => {
31
+ const { data: profile, error } = await betterFetch("https://slack.com/api/openid.connect.userInfo", { headers: { Authorization: `Bearer ${tokens.accessToken}` } });
32
+ if (error || !profile) return null;
33
+ return {
34
+ sub: profile.sub,
35
+ name: profile.name,
36
+ email: profile.email,
37
+ image: profile.picture ?? profile["https://slack.com/user_image_512"],
38
+ emailVerified: profile.email_verified ?? false
39
+ };
40
+ };
41
+ return {
42
+ providerId: "slack",
43
+ accountSubject: ({ profile }) => profile.sub ?? "",
44
+ authorizationUrl: "https://slack.com/openid/connect/authorize",
45
+ tokenUrl: "https://slack.com/api/openid.connect.token",
46
+ userInfoUrl: "https://slack.com/api/openid.connect.userInfo",
47
+ clientId: options.clientId,
48
+ clientSecret: options.clientSecret,
49
+ tokenEndpointAuth: options.tokenEndpointAuth,
50
+ scopes: options.scopes ?? defaultScopes,
51
+ redirectURI: options.redirectURI,
52
+ endSessionEndpoint: options.endSessionEndpoint,
53
+ postLogoutRedirectURI: options.postLogoutRedirectURI,
54
+ disableProviderLogout: options.disableProviderLogout,
55
+ pkce: options.pkce,
56
+ disableImplicitSignUp: options.disableImplicitSignUp,
57
+ disableSignUp: options.disableSignUp,
58
+ overrideUserInfo: options.overrideUserInfo,
59
+ getUserInfo
60
+ };
61
+ }
62
+ //#endregion
63
+ export { slack };
@@ -0,0 +1,29 @@
1
+ import { GenericOAuthConfig } from "../types.mjs";
2
+ import { BaseOAuthProviderOptions } from "../index.mjs";
3
+
4
+ //#region src/plugins/generic-oauth/providers/yandex.d.ts
5
+ interface YandexOptions extends BaseOAuthProviderOptions {}
6
+ /**
7
+ * Yandex OAuth provider helper
8
+ *
9
+ * @example
10
+ * ```ts
11
+ * import { genericOAuth, yandex } from "better-auth/plugins/generic-oauth";
12
+ *
13
+ * export const auth = betterAuth({
14
+ * plugins: [
15
+ * genericOAuth({
16
+ * config: [
17
+ * yandex({
18
+ * clientId: process.env.YANDEX_CLIENT_ID,
19
+ * clientSecret: process.env.YANDEX_CLIENT_SECRET,
20
+ * }),
21
+ * ],
22
+ * }),
23
+ * ],
24
+ * });
25
+ * ```
26
+ */
27
+ declare function yandex(options: YandexOptions): GenericOAuthConfig;
28
+ //#endregion
29
+ export { YandexOptions, yandex };
@@ -0,0 +1,67 @@
1
+ import { betterFetch } from "@better-fetch/fetch";
2
+ //#region src/plugins/generic-oauth/providers/yandex.ts
3
+ /**
4
+ * Yandex OAuth provider helper
5
+ *
6
+ * @example
7
+ * ```ts
8
+ * import { genericOAuth, yandex } from "better-auth/plugins/generic-oauth";
9
+ *
10
+ * export const auth = betterAuth({
11
+ * plugins: [
12
+ * genericOAuth({
13
+ * config: [
14
+ * yandex({
15
+ * clientId: process.env.YANDEX_CLIENT_ID,
16
+ * clientSecret: process.env.YANDEX_CLIENT_SECRET,
17
+ * }),
18
+ * ],
19
+ * }),
20
+ * ],
21
+ * });
22
+ * ```
23
+ */
24
+ function yandex(options) {
25
+ const defaultScopes = [
26
+ "login:info",
27
+ "login:email",
28
+ "login:avatar"
29
+ ];
30
+ const getUserInfo = async (tokens) => {
31
+ const { data: profile, error } = await betterFetch("https://login.yandex.ru/info?format=json", {
32
+ method: "GET",
33
+ headers: { Authorization: `OAuth ${tokens.accessToken}` }
34
+ });
35
+ if (error || !profile) return null;
36
+ const email = profile.default_email ?? profile.emails?.[0];
37
+ if (!email) return null;
38
+ return {
39
+ id: profile.id,
40
+ name: profile.display_name ?? profile.real_name ?? profile.first_name ?? profile.login,
41
+ email,
42
+ emailVerified: false,
43
+ image: !profile.is_avatar_empty && profile.default_avatar_id ? `https://avatars.yandex.net/get-yapic/${profile.default_avatar_id}/islands-200` : void 0
44
+ };
45
+ };
46
+ return {
47
+ providerId: "yandex",
48
+ accountSubject: ({ profile }) => profile.id ?? "",
49
+ authorizationUrl: "https://oauth.yandex.com/authorize",
50
+ tokenUrl: "https://oauth.yandex.com/token",
51
+ clientId: options.clientId,
52
+ clientSecret: options.clientSecret,
53
+ tokenEndpointAuth: options.tokenEndpointAuth,
54
+ scopes: options.scopes ?? defaultScopes,
55
+ redirectURI: options.redirectURI,
56
+ endSessionEndpoint: options.endSessionEndpoint,
57
+ postLogoutRedirectURI: options.postLogoutRedirectURI,
58
+ disableProviderLogout: options.disableProviderLogout,
59
+ pkce: options.pkce,
60
+ disableImplicitSignUp: options.disableImplicitSignUp,
61
+ disableSignUp: options.disableSignUp,
62
+ overrideUserInfo: options.overrideUserInfo,
63
+ getUserInfo
64
+ };
65
+ }
66
+ //#endregion
67
+ export { yandex };
@@ -0,0 +1,268 @@
1
+ import { Awaitable } from "@better-auth/core";
2
+ import { OAuth2Tokens, OAuth2UserInfo, OAuthAccountKeyContext, OAuthMappedUser, OAuthRefreshContext, TokenEndpointAuth } from "@better-auth/core/oauth2";
3
+
4
+ //#region src/plugins/generic-oauth/types.d.ts
5
+ /** Raw profile returned by a Generic OAuth provider. */
6
+ type GenericOAuthUserInfo = Omit<OAuth2UserInfo, "id"> & {
7
+ id?: string | number | null | undefined;
8
+ sub?: string | number | null | undefined;
9
+ [key: string]: unknown;
10
+ };
11
+ interface GenericOAuthOptions<ID extends string = string> {
12
+ /**
13
+ * Array of OAuth provider configurations.
14
+ */
15
+ config: GenericOAuthConfig<ID>[];
16
+ }
17
+ /**
18
+ * Configuration interface for generic OAuth providers.
19
+ */
20
+ interface GenericOAuthConfig<ID extends string = string> {
21
+ /** Unique identifier for the OAuth provider */
22
+ providerId: ID;
23
+ /**
24
+ * Human-readable display name for this provider.
25
+ * Defaults to `providerId` if not set.
26
+ */
27
+ name?: string | undefined;
28
+ /**
29
+ * Stable subject assigned by the provider.
30
+ *
31
+ * OpenID Connect discovery providers use the verified profile's `sub` field
32
+ * by default. Plain OAuth providers use `id`. Configure this resolver when
33
+ * the provider uses a different immutable identifier. Better Auth never
34
+ * switches between fields at runtime because that could change an account's
35
+ * identity. The resolver never receives the mapped local user, so profile
36
+ * mapping cannot redefine provider identity.
37
+ */
38
+ accountSubject?: ((context: OAuthAccountKeyContext<GenericOAuthUserInfo>) => Awaitable<string | number>) | undefined;
39
+ /**
40
+ * URL to fetch OAuth 2.0 configuration.
41
+ * If provided, the authorization and token endpoints will be fetched from this URL.
42
+ */
43
+ discoveryUrl?: string | undefined;
44
+ /**
45
+ * Require discovery to provide the issuer and JWKS metadata needed to verify
46
+ * ID tokens before this provider is registered.
47
+ *
48
+ * Enable this when provider identity is derived from ID-token claims. This
49
+ * prevents an unavailable or incomplete discovery document from silently
50
+ * downgrading the provider to unverified token decoding.
51
+ *
52
+ * @default false
53
+ */
54
+ requireIdTokenVerification?: boolean | undefined;
55
+ /**
56
+ * URL for the authorization endpoint.
57
+ * Optional if using discoveryUrl.
58
+ */
59
+ authorizationUrl?: string | undefined;
60
+ /**
61
+ * URL for the token endpoint.
62
+ * Optional if using discoveryUrl.
63
+ */
64
+ tokenUrl?: string | undefined;
65
+ /**
66
+ * URL for the user info endpoint.
67
+ * Optional if using discoveryUrl.
68
+ */
69
+ userInfoUrl?: string | undefined;
70
+ /**
71
+ * URL for the OIDC RP-Initiated Logout endpoint.
72
+ * Optional if using discoveryUrl and the discovery document includes
73
+ * `end_session_endpoint`.
74
+ */
75
+ endSessionEndpoint?: string | undefined;
76
+ /**
77
+ * URL the provider should redirect back to after logout.
78
+ * This must also be registered with the provider as a post-logout redirect URI.
79
+ */
80
+ postLogoutRedirectURI?: string | undefined;
81
+ /**
82
+ * Disable automatic provider logout on `authClient.signOut()`.
83
+ * When set, sign out only clears the Better Auth session.
84
+ */
85
+ disableProviderLogout?: boolean | undefined;
86
+ /** OAuth client ID */
87
+ clientId: string;
88
+ /** OAuth client secret */
89
+ clientSecret?: string | undefined;
90
+ /**
91
+ * Token endpoint client authentication method.
92
+ *
93
+ * Use `private_key_jwt` for IdPs that authenticate clients with RFC 7523
94
+ * client assertions instead of a client secret. Secret-based methods require
95
+ * clientSecret.
96
+ */
97
+ tokenEndpointAuth?: TokenEndpointAuth | undefined;
98
+ /**
99
+ * Array of OAuth scopes to request.
100
+ * @default []
101
+ */
102
+ scopes?: string[] | undefined;
103
+ /**
104
+ * Custom redirect URI.
105
+ * If not provided, a default URI will be constructed.
106
+ */
107
+ redirectURI?: string | undefined;
108
+ /**
109
+ * OAuth response type.
110
+ * @default "code"
111
+ */
112
+ responseType?: string | undefined;
113
+ /**
114
+ * The response mode to use for the authorization code request.
115
+ */
116
+ responseMode?: ("query" | "form_post") | undefined;
117
+ /**
118
+ * Prompt parameter for the authorization request.
119
+ * Controls the authentication experience for the user.
120
+ */
121
+ prompt?: ("none" | "login" | "create" | "consent" | "select_account" | "select_account consent" | "login consent") | undefined;
122
+ /**
123
+ * Whether to use PKCE (Proof Key for Code Exchange).
124
+ * Required by OAuth 2.1 for all authorization code flows.
125
+ * Disable only for providers that explicitly reject PKCE.
126
+ * @default true
127
+ */
128
+ pkce?: boolean | undefined;
129
+ /**
130
+ * Access type for the authorization request.
131
+ * Use "offline" to request a refresh token.
132
+ */
133
+ accessType?: string | undefined;
134
+ /**
135
+ * Fallback access-token lifetime, in seconds, used only when the provider's
136
+ * token response omits `expires_in`. Set this so `getAccessToken` can track
137
+ * expiry and refresh the token; leave unset if the provider returns
138
+ * `expires_in`.
139
+ */
140
+ accessTokenExpiresIn?: number | undefined;
141
+ /**
142
+ * Custom function to exchange authorization code for tokens.
143
+ * If provided, this function will be used instead of the default token exchange logic.
144
+ * This is useful for providers with non-standard token endpoints.
145
+ * @param data - Authorization code exchange parameters
146
+ * @returns A promise that resolves to OAuth2Tokens
147
+ */
148
+ getToken?: ((data: {
149
+ code: string;
150
+ redirectURI: string;
151
+ codeVerifier?: string | undefined;
152
+ deviceId?: string | undefined;
153
+ }) => Promise<OAuth2Tokens>) | undefined;
154
+ /**
155
+ * Custom function to fetch user info.
156
+ * If provided, this function will be used instead of the default user info fetching logic.
157
+ * @param tokens - The OAuth tokens received after successful authentication
158
+ * @returns A promise that resolves to a raw provider profile or null
159
+ */
160
+ getUserInfo?: ((tokens: OAuth2Tokens) => Promise<GenericOAuthUserInfo | null>) | undefined;
161
+ /**
162
+ * Custom function to map the provider's user profile to your app's user fields.
163
+ * The profile contains standard OAuth2 fields plus any provider-specific extras.
164
+ */
165
+ mapProfileToUser?: ((profile: GenericOAuthUserInfo) => OAuthMappedUser | Promise<OAuthMappedUser>) | undefined;
166
+ /**
167
+ * Additional search-params to add to the authorizationUrl.
168
+ * Warning: Search-params added here overwrite any default params.
169
+ */
170
+ authorizationUrlParams?: Record<string, string> | undefined;
171
+ /**
172
+ * Additional search-params to add to the tokenUrl.
173
+ * Parameters already set by Better Auth are preserved. Configure token
174
+ * endpoint client authentication with clientId, clientSecret, and
175
+ * tokenEndpointAuth.
176
+ */
177
+ tokenUrlParams?: Record<string, string> | undefined;
178
+ /**
179
+ * Additional body params merged into the token endpoint request when
180
+ * refreshing an access token. Useful for multi-tenant OIDC providers that
181
+ * need to change `scope`, `audience`, `resource`, or a tenant identifier on
182
+ * the refresh call — e.g. Zitadel's `urn:zitadel:iam:org:id:{orgId}` scope
183
+ * on workspace switch or Auth0 `audience` rotation — without forcing a new
184
+ * authorization redirect.
185
+ *
186
+ * The function form is invoked at refresh time and receives request
187
+ * metadata for the triggering request, so dynamic
188
+ * per-request values like an active organization id read from cookies or
189
+ * headers can be injected directly. Headers and cookies are
190
+ * attacker-controlled: callers MUST validate any value derived from them
191
+ * against the authenticated user's entitlements before forwarding it as a
192
+ * `scope`, `audience`, or tenant claim. Resolved values are merged into the
193
+ * form body; `grant_type` and `refresh_token` are protected from override,
194
+ * and `client_id` is set by the configured token-endpoint authentication
195
+ * after the merge so it cannot be overridden here.
196
+ */
197
+ refreshTokenParams?: Record<string, string> | ((ctx?: OAuthRefreshContext) => Awaitable<Record<string, string> | undefined>) | undefined;
198
+ /**
199
+ * Disable implicit sign up for new users. When set to true for the provider,
200
+ * sign-in need to be called with with requestSignUp as true to create new users.
201
+ */
202
+ disableImplicitSignUp?: boolean | undefined;
203
+ /**
204
+ * Disable sign up for new users.
205
+ */
206
+ disableSignUp?: boolean | undefined;
207
+ /**
208
+ * Authentication method for token requests.
209
+ * "basic" requires clientSecret.
210
+ * @default "post"
211
+ */
212
+ authentication?: ("basic" | "post") | undefined;
213
+ /**
214
+ * Custom headers to include in the discovery request.
215
+ * Useful for providers like Epic that require specific headers (e.g., Epic-Client-ID).
216
+ */
217
+ discoveryHeaders?: Record<string, string> | undefined;
218
+ /**
219
+ * Custom headers to include in the authorization request.
220
+ * Useful for providers like Qonto that require specific headers (e.g., X-Qonto-Staging-Token for local development).
221
+ */
222
+ authorizationHeaders?: Record<string, string> | undefined;
223
+ /**
224
+ * Override user info with the provider info.
225
+ *
226
+ * This will update the user info with the provider info,
227
+ * when the user signs in with the provider.
228
+ * @default false
229
+ */
230
+ overrideUserInfo?: boolean | undefined;
231
+ /**
232
+ * Require this provider's email to be verified before a session is created.
233
+ *
234
+ * When the provider reports the email as unverified, the user and account are
235
+ * still created or linked, but no session is issued: the callback redirects
236
+ * with `?error=email_not_verified`. The gate checks the local user's
237
+ * verification state, so a user already verified through another method keeps
238
+ * access. Only enable it for providers that report a trustworthy
239
+ * `email_verified` signal.
240
+ *
241
+ * @default false
242
+ */
243
+ requireEmailVerification?: boolean | undefined;
244
+ /**
245
+ * Accept callbacks from providers that initiate the OAuth flow without
246
+ * sending a `state` parameter (e.g. Clever). When enabled, stateless
247
+ * callbacks restart the OAuth flow server-side with a fresh `state` and
248
+ * PKCE verifier. See the generic-oauth docs for details.
249
+ *
250
+ * @default false
251
+ */
252
+ allowIdpInitiated?: boolean | undefined;
253
+ /**
254
+ * Disable OIDC `nonce` binding for this provider's `id_token`.
255
+ *
256
+ * Providers configured with `discoveryUrl` that publish a JWKS bind the
257
+ * `id_token` to the authorization request by default: Better Auth sends a
258
+ * server-generated `nonce` and rejects a callback whose `id_token` does not
259
+ * echo it (OIDC Core 1.0 §3.1.3.7). Set this to `true` only for OIDC
260
+ * providers that do not return the `nonce` claim in the authorization-code
261
+ * flow; doing so removes `id_token` replay protection for this provider.
262
+ *
263
+ * @default false
264
+ */
265
+ disableIdTokenNonceBinding?: boolean | undefined;
266
+ }
267
+ //#endregion
268
+ export { GenericOAuthConfig, GenericOAuthOptions, GenericOAuthUserInfo };
@@ -0,0 +1,63 @@
1
+ import * as _$_better_auth_core0 from "@better-auth/core";
2
+ import * as _$_better_auth_core_utils_error_codes0 from "@better-auth/core/utils/error-codes";
3
+
4
+ //#region src/plugins/haveibeenpwned/index.d.ts
5
+ declare module "@better-auth/core" {
6
+ interface BetterAuthPluginRegistry<AuthOptions, Options> {
7
+ "have-i-been-pwned": {
8
+ creator: typeof haveIBeenPwned;
9
+ };
10
+ }
11
+ }
12
+ /**
13
+ * Checks whether a password appears in the Have I Been Pwned password corpus.
14
+ * Only the first five characters of its SHA-1 hash are sent to the service.
15
+ *
16
+ * @returns Whether the password has been compromised.
17
+ * @throws {APIError} When the password could not be checked.
18
+ */
19
+ declare function isPasswordCompromised(password: string): Promise<boolean>;
20
+ interface HaveIBeenPwnedOptions {
21
+ /**
22
+ * Custom error message shown when a compromised password is detected.
23
+ */
24
+ customPasswordCompromisedMessage?: string | undefined;
25
+ /**
26
+ * Paths to check for password
27
+ *
28
+ * @default ["/sign-up/email", "/change-password", "/reset-password", "/email-otp/reset-password", "/phone-number/reset-password", "/admin/create-user", "/admin/set-user-password"]
29
+ */
30
+ paths?: string[];
31
+ /**
32
+ * Enable or disable password checks against the HIBP database.
33
+ *
34
+ * @default true
35
+ */
36
+ enabled?: boolean | undefined;
37
+ }
38
+ declare const haveIBeenPwned: (options?: HaveIBeenPwnedOptions | undefined) => {
39
+ id: "have-i-been-pwned";
40
+ version: string;
41
+ init(ctx: _$_better_auth_core0.AuthContext): {
42
+ context: {
43
+ password: {
44
+ hash(password: string): Promise<string>;
45
+ verify: (data: {
46
+ password: string;
47
+ hash: string;
48
+ }) => Promise<boolean>;
49
+ config: {
50
+ minPasswordLength: number;
51
+ maxPasswordLength: number;
52
+ };
53
+ checkPassword: (userId: string, ctx: _$_better_auth_core0.GenericEndpointContext<_$_better_auth_core0.BetterAuthOptions>) => Promise<boolean>;
54
+ };
55
+ };
56
+ };
57
+ options: HaveIBeenPwnedOptions | undefined;
58
+ $ERROR_CODES: {
59
+ PASSWORD_COMPROMISED: _$_better_auth_core_utils_error_codes0.RawError<"PASSWORD_COMPROMISED">;
60
+ };
61
+ };
62
+ //#endregion
63
+ export { HaveIBeenPwnedOptions, haveIBeenPwned, isPasswordCompromised };
@@ -0,0 +1,81 @@
1
+ import { isAPIError } from "../../utils/is-api-error.mjs";
2
+ import { APIError } from "../../api/index.mjs";
3
+ import { PACKAGE_VERSION } from "../../version.mjs";
4
+ import { getCurrentAuthEndpointContext } from "@better-auth/core/context";
5
+ import { defineErrorCodes } from "@better-auth/core/utils/error-codes";
6
+ import { createHash } from "@better-auth/utils/hash";
7
+ import { betterFetch } from "@better-fetch/fetch";
8
+ //#region src/plugins/haveibeenpwned/index.ts
9
+ const ERROR_CODES = defineErrorCodes({ PASSWORD_COMPROMISED: "The password you entered has been compromised. Please choose a different password." });
10
+ function getPasswordCompromiseCount(response, hashSuffix) {
11
+ const matchingEntryPrefix = `${hashSuffix.toUpperCase()}:`;
12
+ for (const line of response.split(/\r?\n/)) {
13
+ if (line.slice(0, matchingEntryPrefix.length).toUpperCase() !== matchingEntryPrefix) continue;
14
+ const compromiseCountText = line.slice(matchingEntryPrefix.length);
15
+ const compromiseCount = Number(compromiseCountText);
16
+ if (!(Number.isSafeInteger(compromiseCount) && compromiseCount >= 0 && String(compromiseCount) === compromiseCountText)) throw new Error("Invalid password compromise count");
17
+ return compromiseCount;
18
+ }
19
+ return 0;
20
+ }
21
+ /**
22
+ * Checks whether a password appears in the Have I Been Pwned password corpus.
23
+ * Only the first five characters of its SHA-1 hash are sent to the service.
24
+ *
25
+ * @returns Whether the password has been compromised.
26
+ * @throws {APIError} When the password could not be checked.
27
+ */
28
+ async function isPasswordCompromised(password) {
29
+ try {
30
+ const sha1Hash = (await createHash("SHA-1", "hex").digest(password)).toUpperCase();
31
+ const prefix = sha1Hash.substring(0, 5);
32
+ const suffix = sha1Hash.substring(5);
33
+ const { data, error } = await betterFetch(`https://api.pwnedpasswords.com/range/${prefix}`, { headers: {
34
+ "Add-Padding": "true",
35
+ "User-Agent": "BetterAuth Password Checker"
36
+ } });
37
+ if (error) throw new APIError("INTERNAL_SERVER_ERROR", { message: `Failed to check password. Status: ${error.status}` });
38
+ return getPasswordCompromiseCount(data, suffix) > 0;
39
+ } catch (error) {
40
+ if (isAPIError(error)) throw error;
41
+ throw new APIError("INTERNAL_SERVER_ERROR", { message: "Failed to check password. Please try again later." });
42
+ }
43
+ }
44
+ async function rejectCompromisedPassword(password, customMessage) {
45
+ if (await isPasswordCompromised(password)) throw APIError.from("BAD_REQUEST", {
46
+ message: customMessage || ERROR_CODES.PASSWORD_COMPROMISED.message,
47
+ code: ERROR_CODES.PASSWORD_COMPROMISED.code
48
+ });
49
+ }
50
+ const haveIBeenPwned = (options) => {
51
+ const paths = options?.paths || [
52
+ "/sign-up/email",
53
+ "/change-password",
54
+ "/reset-password",
55
+ "/email-otp/reset-password",
56
+ "/phone-number/reset-password",
57
+ "/admin/create-user",
58
+ "/admin/set-user-password"
59
+ ];
60
+ return {
61
+ id: "have-i-been-pwned",
62
+ version: PACKAGE_VERSION,
63
+ init(ctx) {
64
+ const originalHash = ctx.password.hash;
65
+ return { context: { password: {
66
+ ...ctx.password,
67
+ async hash(password) {
68
+ if (options?.enabled === false) return originalHash(password);
69
+ const c = getCurrentAuthEndpointContext();
70
+ if (!c.path || !paths.includes(c.path)) return originalHash(password);
71
+ await rejectCompromisedPassword(password, options?.customPasswordCompromisedMessage);
72
+ return originalHash(password);
73
+ }
74
+ } } };
75
+ },
76
+ options,
77
+ $ERROR_CODES: ERROR_CODES
78
+ };
79
+ };
80
+ //#endregion
81
+ export { haveIBeenPwned, isPasswordCompromised };
@@ -0,0 +1,69 @@
1
+ import { InferOptionSchema, InferPluginContext, InferPluginErrorCodes, InferPluginIDs } from "../types/plugins.mjs";
2
+ import { HIDE_METADATA } from "../utils/hide-metadata.mjs";
3
+ import { AccessControl, ArrayElement, ExactRoleStatements, Role, RoleAuthorizeRequest, RoleInput, RoleStatements, Statements, SubArray, Subset } from "./access/types.mjs";
4
+ import { AuthorizeResponse, createAccessControl, role } from "./access/access.mjs";
5
+ import { OrganizationOptions } from "./organization/types.mjs";
6
+ import { InferInvitation, InferMember, InferOrganization, InferOrganizationRolesFromOption, InferOrganizationZodRolesFromOption, InferTeam, Invitation, InvitationInput, InvitationStatus, Member, MemberInput, Organization, OrganizationInput, OrganizationRole, OrganizationSchema, Team, TeamInput, TeamMember, TeamMemberInput, defaultRolesSchema, invitationSchema, invitationStatus, memberSchema, organizationRoleSchema, organizationSchema, roleSchema, teamMemberSchema, teamSchema } from "./organization/schema.mjs";
7
+ import { getOrgAdapter } from "./organization/adapter.mjs";
8
+ import { AdminOptions, InferAdminRolesFromOption, SessionWithImpersonatedBy, UserWithRole } from "./admin/types.mjs";
9
+ import { admin } from "./admin/admin.mjs";
10
+ import { AnonymousOptions, AnonymousSession, UserWithAnonymous } from "./anonymous/types.mjs";
11
+ import { anonymous } from "./anonymous/index.mjs";
12
+ import { BearerOptions, bearer } from "./bearer/index.mjs";
13
+ import { BaseCaptchaOptions, CaptchaFoxOptions, CaptchaOptions, CloudflareTurnstileOptions, GoogleRecaptchaOptions, HCaptchaOptions, Provider } from "./captcha/types.mjs";
14
+ import { captcha } from "./captcha/index.mjs";
15
+ import { CustomSessionPluginOptions, customSession } from "./custom-session/index.mjs";
16
+ import { TimeString, ms, sec } from "../utils/time.mjs";
17
+ import { DeviceCode } from "./device-authorization/schema.mjs";
18
+ import { DeviceCodeRedemptionAuthorization, DeviceCodeRedemptionResult, redeemDeviceCode } from "./device-authorization/routes.mjs";
19
+ import { DeviceAuthorizationGrant, DeviceAuthorizationGrantAuthorization, DeviceAuthorizationOptions, DeviceAuthorizationPluginOptions, DeviceAuthorizationRequest, deviceAuthorization, deviceAuthorizationOptionsSchema } from "./device-authorization/index.mjs";
20
+ import { EmailOTPOptions } from "./email-otp/types.mjs";
21
+ import { emailOTP } from "./email-otp/index.mjs";
22
+ import { GenericOAuthConfig, GenericOAuthOptions, GenericOAuthUserInfo } from "./generic-oauth/types.mjs";
23
+ import { Auth0Options, auth0 } from "./generic-oauth/providers/auth0.mjs";
24
+ import { GumroadOptions, gumroad } from "./generic-oauth/providers/gumroad.mjs";
25
+ import { HubSpotOptions, hubspot } from "./generic-oauth/providers/hubspot.mjs";
26
+ import { KeycloakOptions, keycloak } from "./generic-oauth/providers/keycloak.mjs";
27
+ import { LineOptions, line } from "./generic-oauth/providers/line.mjs";
28
+ import { MicrosoftEntraIdOptions, microsoftEntraId } from "./generic-oauth/providers/microsoft-entra-id.mjs";
29
+ import { OktaOptions, okta } from "./generic-oauth/providers/okta.mjs";
30
+ import { PatreonOptions, patreon } from "./generic-oauth/providers/patreon.mjs";
31
+ import { SlackOptions, slack } from "./generic-oauth/providers/slack.mjs";
32
+ import { YandexOptions, yandex } from "./generic-oauth/providers/yandex.mjs";
33
+ import { BaseOAuthProviderOptions, genericOAuth } from "./generic-oauth/index.mjs";
34
+ import { HaveIBeenPwnedOptions, haveIBeenPwned, isPasswordCompromised } from "./haveibeenpwned/index.mjs";
35
+ import { JWKOptions, JWSAlgorithms, Jwk, JwtOptions, ResolvedSigningKey } from "./jwt/types.mjs";
36
+ import { getJwtToken, resolveSigningKey, signJWT } from "./jwt/sign.mjs";
37
+ import { createJwk, generateExportedKeyPair, toExpJWT } from "./jwt/utils.mjs";
38
+ import { verifyJWT } from "./jwt/verify.mjs";
39
+ import { jwt } from "./jwt/index.mjs";
40
+ import { LastLoginMethodOptions, lastLoginMethod } from "./last-login-method/index.mjs";
41
+ import { MagicLinkOptions, magicLink } from "./magic-link/index.mjs";
42
+ import { MULTI_SESSION_ERROR_CODES } from "./multi-session/error-codes.mjs";
43
+ import { MultiSessionConfig, multiSession } from "./multi-session/index.mjs";
44
+ import { OAUTH_POPUP_DATA_ELEMENT_ID, OAUTH_POPUP_MESSAGE_TYPE, POPUP_MARKER_COOKIE } from "./oauth-popup/constants.mjs";
45
+ import { OAUTH_POPUP_ERROR_CODES } from "./oauth-popup/error-codes.mjs";
46
+ import { OAuthPopupData, OAuthPopupMessage } from "./oauth-popup/types.mjs";
47
+ import { OAUTH_POPUP_COMPLETE_SCRIPT, OAUTH_POPUP_SCRIPT_CSP_HASH, oauthPopup } from "./oauth-popup/index.mjs";
48
+ import { OAuthProxyOptions, oAuthProxy } from "./oauth-proxy/index.mjs";
49
+ import { OneTapOptions, oneTap } from "./one-tap/index.mjs";
50
+ import { OneTimeTokenOptions, oneTimeToken } from "./one-time-token/index.mjs";
51
+ import { FieldSchema, OpenAPIModelSchema, OpenAPIParameter, OpenAPISchema, Path, generator } from "./open-api/generator.mjs";
52
+ import { OpenAPIOptions, openAPI } from "./open-api/index.mjs";
53
+ import { PhoneNumberOptions, UserWithPhoneNumber } from "./phone-number/types.mjs";
54
+ import { phoneNumber } from "./phone-number/index.mjs";
55
+ import { SIWEPluginOptions, siwe } from "./siwe/index.mjs";
56
+ import { LoginResult, TestAuthOptions, TestCookie, TestHelpers, TestUtilsOptions } from "./test-utils/types.mjs";
57
+ import { testUtils } from "./test-utils/index.mjs";
58
+ import { BackupCodeOptions, backupCode2fa, encodeBackupCodes, generateBackupCodes, getBackupCodes, verifyBackupCode } from "./two-factor/backup-codes/index.mjs";
59
+ import { OTPOptions, otp2fa } from "./two-factor/otp/index.mjs";
60
+ import { TOTPOptions, totp2fa } from "./two-factor/totp/index.mjs";
61
+ import { TwoFactorOptions, TwoFactorProvider, TwoFactorTable, UserWithTwoFactor } from "./two-factor/types.mjs";
62
+ import { TWO_FACTOR_ERROR_CODES } from "./two-factor/error-code.mjs";
63
+ import { twoFactorClient } from "./two-factor/client.mjs";
64
+ import { twoFactor } from "./two-factor/index.mjs";
65
+ import { USERNAME_ERROR_CODES } from "./username/error-codes.mjs";
66
+ import { UsernameOptions, UsernamePlugin, UsernamePluginWithoutDisplayUsername, username } from "./username/index.mjs";
67
+ import { hasPermission } from "./organization/has-permission.mjs";
68
+ import { DefaultOrganizationPlugin, DynamicAccessControlEndpoints, OrganizationCreator, OrganizationEndpoints, OrganizationPlugin, TeamEndpoints, organization, parseRoles } from "./organization/organization.mjs";
69
+ export { AccessControl, AdminOptions, AnonymousOptions, AnonymousSession, ArrayElement, Auth0Options, AuthorizeResponse, BackupCodeOptions, BaseCaptchaOptions, BaseOAuthProviderOptions, BearerOptions, CaptchaFoxOptions, CaptchaOptions, CloudflareTurnstileOptions, CustomSessionPluginOptions, DefaultOrganizationPlugin, DeviceAuthorizationGrant, DeviceAuthorizationGrantAuthorization, DeviceAuthorizationOptions, DeviceAuthorizationPluginOptions, DeviceAuthorizationRequest, DeviceCode, DeviceCodeRedemptionAuthorization, DeviceCodeRedemptionResult, DynamicAccessControlEndpoints, MULTI_SESSION_ERROR_CODES as ERROR_CODES, EmailOTPOptions, ExactRoleStatements, FieldSchema, GenericOAuthConfig, GenericOAuthOptions, GenericOAuthUserInfo, GoogleRecaptchaOptions, GumroadOptions, HCaptchaOptions, HIDE_METADATA, HaveIBeenPwnedOptions, HubSpotOptions, InferAdminRolesFromOption, InferInvitation, InferMember, InferOptionSchema, InferOrganization, InferOrganizationRolesFromOption, InferOrganizationZodRolesFromOption, InferPluginContext, InferPluginErrorCodes, InferPluginIDs, InferTeam, Invitation, InvitationInput, InvitationStatus, JWKOptions, JWSAlgorithms, Jwk, JwtOptions, KeycloakOptions, LastLoginMethodOptions, LineOptions, LoginResult, MagicLinkOptions, Member, MemberInput, MicrosoftEntraIdOptions, MultiSessionConfig, OAUTH_POPUP_COMPLETE_SCRIPT, OAUTH_POPUP_DATA_ELEMENT_ID, OAUTH_POPUP_ERROR_CODES, OAUTH_POPUP_MESSAGE_TYPE, OAUTH_POPUP_SCRIPT_CSP_HASH, OAuthPopupData, OAuthPopupMessage, OAuthProxyOptions, OTPOptions, OktaOptions, OneTapOptions, OneTimeTokenOptions, OpenAPIModelSchema, OpenAPIOptions, OpenAPIParameter, OpenAPISchema, Organization, OrganizationCreator, OrganizationEndpoints, OrganizationInput, OrganizationOptions, OrganizationPlugin, OrganizationRole, OrganizationSchema, POPUP_MARKER_COOKIE, Path, PatreonOptions, PhoneNumberOptions, Provider, ResolvedSigningKey, Role, RoleAuthorizeRequest, RoleInput, RoleStatements, SIWEPluginOptions, SessionWithImpersonatedBy, SlackOptions, Statements, SubArray, Subset, TOTPOptions, TWO_FACTOR_ERROR_CODES, Team, TeamEndpoints, TeamInput, TeamMember, TeamMemberInput, TestAuthOptions, TestCookie, TestHelpers, TestUtilsOptions, TimeString, TwoFactorOptions, TwoFactorProvider, TwoFactorTable, USERNAME_ERROR_CODES, UserWithAnonymous, UserWithPhoneNumber, UserWithRole, UserWithTwoFactor, UsernameOptions, UsernamePlugin, UsernamePluginWithoutDisplayUsername, YandexOptions, admin, anonymous, auth0, backupCode2fa, bearer, captcha, createAccessControl, createJwk, customSession, defaultRolesSchema, deviceAuthorization, deviceAuthorizationOptionsSchema, emailOTP, encodeBackupCodes, generateBackupCodes, generateExportedKeyPair, generator, genericOAuth, getBackupCodes, getJwtToken, getOrgAdapter, gumroad, hasPermission, haveIBeenPwned, hubspot, invitationSchema, invitationStatus, isPasswordCompromised, jwt, keycloak, lastLoginMethod, line, magicLink, memberSchema, microsoftEntraId, ms, multiSession, oAuthProxy, oauthPopup, okta, oneTap, oneTimeToken, openAPI, organization, organizationRoleSchema, organizationSchema, otp2fa, parseRoles, patreon, phoneNumber, redeemDeviceCode, resolveSigningKey, role, roleSchema, sec, signJWT, siwe, slack, teamMemberSchema, teamSchema, testUtils, toExpJWT, totp2fa, twoFactor, twoFactorClient, username, verifyBackupCode, verifyJWT, yandex };