@sirketio/auth 0.0.1

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 (594) hide show
  1. package/dist/_virtual/_rolldown/runtime.mjs +36 -0
  2. package/dist/adapter/index.d.mts +4 -0
  3. package/dist/adapter/index.mjs +7 -0
  4. package/dist/api/index.d.mts +3872 -0
  5. package/dist/api/index.mjs +206 -0
  6. package/dist/api/index.mjs.map +1 -0
  7. package/dist/api/middlewares/index.d.mts +1 -0
  8. package/dist/api/middlewares/index.mjs +3 -0
  9. package/dist/api/middlewares/origin-check.d.mts +18 -0
  10. package/dist/api/middlewares/origin-check.mjs +140 -0
  11. package/dist/api/middlewares/origin-check.mjs.map +1 -0
  12. package/dist/api/rate-limiter/index.mjs +204 -0
  13. package/dist/api/rate-limiter/index.mjs.map +1 -0
  14. package/dist/api/routes/account.d.mts +410 -0
  15. package/dist/api/routes/account.mjs +493 -0
  16. package/dist/api/routes/account.mjs.map +1 -0
  17. package/dist/api/routes/callback.d.mts +31 -0
  18. package/dist/api/routes/callback.mjs +179 -0
  19. package/dist/api/routes/callback.mjs.map +1 -0
  20. package/dist/api/routes/email-verification.d.mts +161 -0
  21. package/dist/api/routes/email-verification.mjs +299 -0
  22. package/dist/api/routes/email-verification.mjs.map +1 -0
  23. package/dist/api/routes/error.d.mts +28 -0
  24. package/dist/api/routes/error.mjs +386 -0
  25. package/dist/api/routes/error.mjs.map +1 -0
  26. package/dist/api/routes/index.d.mts +11 -0
  27. package/dist/api/routes/index.mjs +13 -0
  28. package/dist/api/routes/ok.d.mts +36 -0
  29. package/dist/api/routes/ok.mjs +30 -0
  30. package/dist/api/routes/ok.mjs.map +1 -0
  31. package/dist/api/routes/password.d.mts +182 -0
  32. package/dist/api/routes/password.mjs +198 -0
  33. package/dist/api/routes/password.mjs.map +1 -0
  34. package/dist/api/routes/session.d.mts +415 -0
  35. package/dist/api/routes/session.mjs +483 -0
  36. package/dist/api/routes/session.mjs.map +1 -0
  37. package/dist/api/routes/sign-in.d.mts +171 -0
  38. package/dist/api/routes/sign-in.mjs +263 -0
  39. package/dist/api/routes/sign-in.mjs.map +1 -0
  40. package/dist/api/routes/sign-out.d.mts +36 -0
  41. package/dist/api/routes/sign-out.mjs +33 -0
  42. package/dist/api/routes/sign-out.mjs.map +1 -0
  43. package/dist/api/routes/sign-up.d.mts +160 -0
  44. package/dist/api/routes/sign-up.mjs +227 -0
  45. package/dist/api/routes/sign-up.mjs.map +1 -0
  46. package/dist/api/routes/update-user.d.mts +445 -0
  47. package/dist/api/routes/update-user.mjs +493 -0
  48. package/dist/api/routes/update-user.mjs.map +1 -0
  49. package/dist/api/state/oauth.d.mts +18 -0
  50. package/dist/api/state/oauth.mjs +8 -0
  51. package/dist/api/state/oauth.mjs.map +1 -0
  52. package/dist/api/state/should-session-refresh.d.mts +13 -0
  53. package/dist/api/state/should-session-refresh.mjs +16 -0
  54. package/dist/api/state/should-session-refresh.mjs.map +1 -0
  55. package/dist/api/to-auth-endpoints.mjs +197 -0
  56. package/dist/api/to-auth-endpoints.mjs.map +1 -0
  57. package/dist/auth/base.mjs +45 -0
  58. package/dist/auth/base.mjs.map +1 -0
  59. package/dist/auth/minimal.d.mts +12 -0
  60. package/dist/auth/minimal.mjs +14 -0
  61. package/dist/auth/minimal.mjs.map +1 -0
  62. package/dist/auth/trusted-origins.mjs +31 -0
  63. package/dist/auth/trusted-origins.mjs.map +1 -0
  64. package/dist/client/broadcast-channel.d.mts +20 -0
  65. package/dist/client/broadcast-channel.mjs +46 -0
  66. package/dist/client/broadcast-channel.mjs.map +1 -0
  67. package/dist/client/config.mjs +90 -0
  68. package/dist/client/config.mjs.map +1 -0
  69. package/dist/client/fetch-plugins.mjs +18 -0
  70. package/dist/client/fetch-plugins.mjs.map +1 -0
  71. package/dist/client/focus-manager.d.mts +11 -0
  72. package/dist/client/focus-manager.mjs +32 -0
  73. package/dist/client/focus-manager.mjs.map +1 -0
  74. package/dist/client/index.d.mts +33 -0
  75. package/dist/client/index.mjs +21 -0
  76. package/dist/client/index.mjs.map +1 -0
  77. package/dist/client/online-manager.d.mts +12 -0
  78. package/dist/client/online-manager.mjs +35 -0
  79. package/dist/client/online-manager.mjs.map +1 -0
  80. package/dist/client/parser.mjs +73 -0
  81. package/dist/client/parser.mjs.map +1 -0
  82. package/dist/client/path-to-object.d.mts +65 -0
  83. package/dist/client/plugins/index.d.mts +53 -0
  84. package/dist/client/plugins/index.mjs +30 -0
  85. package/dist/client/plugins/infer-plugin.d.mts +16 -0
  86. package/dist/client/plugins/infer-plugin.mjs +11 -0
  87. package/dist/client/plugins/infer-plugin.mjs.map +1 -0
  88. package/dist/client/proxy.mjs +79 -0
  89. package/dist/client/proxy.mjs.map +1 -0
  90. package/dist/client/query.d.mts +23 -0
  91. package/dist/client/query.mjs +98 -0
  92. package/dist/client/query.mjs.map +1 -0
  93. package/dist/client/react/index.d.mts +128 -0
  94. package/dist/client/react/index.mjs +24 -0
  95. package/dist/client/react/index.mjs.map +1 -0
  96. package/dist/client/react/react-store.d.mts +47 -0
  97. package/dist/client/react/react-store.mjs +47 -0
  98. package/dist/client/react/react-store.mjs.map +1 -0
  99. package/dist/client/session-atom.mjs +29 -0
  100. package/dist/client/session-atom.mjs.map +1 -0
  101. package/dist/client/session-refresh.d.mts +28 -0
  102. package/dist/client/session-refresh.mjs +140 -0
  103. package/dist/client/session-refresh.mjs.map +1 -0
  104. package/dist/client/types.d.mts +41 -0
  105. package/dist/client/vanilla.d.mts +127 -0
  106. package/dist/client/vanilla.mjs +20 -0
  107. package/dist/client/vanilla.mjs.map +1 -0
  108. package/dist/context/create-context.mjs +211 -0
  109. package/dist/context/create-context.mjs.map +1 -0
  110. package/dist/context/helpers.mjs +83 -0
  111. package/dist/context/helpers.mjs.map +1 -0
  112. package/dist/context/init.mjs +20 -0
  113. package/dist/context/init.mjs.map +1 -0
  114. package/dist/cookies/cookie-utils.d.mts +29 -0
  115. package/dist/cookies/cookie-utils.mjs +105 -0
  116. package/dist/cookies/cookie-utils.mjs.map +1 -0
  117. package/dist/cookies/index.d.mts +121 -0
  118. package/dist/cookies/index.mjs +261 -0
  119. package/dist/cookies/index.mjs.map +1 -0
  120. package/dist/cookies/session-store.d.mts +36 -0
  121. package/dist/cookies/session-store.mjs +200 -0
  122. package/dist/cookies/session-store.mjs.map +1 -0
  123. package/dist/crypto/buffer.d.mts +8 -0
  124. package/dist/crypto/buffer.mjs +18 -0
  125. package/dist/crypto/buffer.mjs.map +1 -0
  126. package/dist/crypto/index.d.mts +27 -0
  127. package/dist/crypto/index.mjs +38 -0
  128. package/dist/crypto/index.mjs.map +1 -0
  129. package/dist/crypto/jwt.d.mts +8 -0
  130. package/dist/crypto/jwt.mjs +95 -0
  131. package/dist/crypto/jwt.mjs.map +1 -0
  132. package/dist/crypto/password.d.mts +12 -0
  133. package/dist/crypto/password.mjs +36 -0
  134. package/dist/crypto/password.mjs.map +1 -0
  135. package/dist/crypto/random.d.mts +5 -0
  136. package/dist/crypto/random.mjs +8 -0
  137. package/dist/crypto/random.mjs.map +1 -0
  138. package/dist/db/adapter-base.d.mts +8 -0
  139. package/dist/db/adapter-base.mjs +19 -0
  140. package/dist/db/adapter-base.mjs.map +1 -0
  141. package/dist/db/field-converter.d.mts +8 -0
  142. package/dist/db/field-converter.mjs +21 -0
  143. package/dist/db/field-converter.mjs.map +1 -0
  144. package/dist/db/field.d.mts +42 -0
  145. package/dist/db/get-schema.d.mts +11 -0
  146. package/dist/db/get-schema.mjs +39 -0
  147. package/dist/db/get-schema.mjs.map +1 -0
  148. package/dist/db/index.d.mts +18 -0
  149. package/dist/db/index.mjs +34 -0
  150. package/dist/db/index.mjs.map +1 -0
  151. package/dist/db/internal-adapter.d.mts +14 -0
  152. package/dist/db/internal-adapter.mjs +616 -0
  153. package/dist/db/internal-adapter.mjs.map +1 -0
  154. package/dist/db/schema.d.mts +49 -0
  155. package/dist/db/schema.mjs +118 -0
  156. package/dist/db/schema.mjs.map +1 -0
  157. package/dist/db/to-zod.d.mts +36 -0
  158. package/dist/db/to-zod.mjs +26 -0
  159. package/dist/db/to-zod.mjs.map +1 -0
  160. package/dist/db/verification-token-storage.mjs +28 -0
  161. package/dist/db/verification-token-storage.mjs.map +1 -0
  162. package/dist/db/with-hooks.d.mts +33 -0
  163. package/dist/db/with-hooks.mjs +159 -0
  164. package/dist/db/with-hooks.mjs.map +1 -0
  165. package/dist/index.d.mts +53 -0
  166. package/dist/index.mjs +27 -0
  167. package/dist/integrations/next-js.d.mts +29 -0
  168. package/dist/integrations/next-js.mjs +85 -0
  169. package/dist/integrations/next-js.mjs.map +1 -0
  170. package/dist/oauth2/index.d.mts +5 -0
  171. package/dist/oauth2/index.mjs +7 -0
  172. package/dist/oauth2/link-account.d.mts +48 -0
  173. package/dist/oauth2/link-account.mjs +143 -0
  174. package/dist/oauth2/link-account.mjs.map +1 -0
  175. package/dist/oauth2/state.d.mts +26 -0
  176. package/dist/oauth2/state.mjs +51 -0
  177. package/dist/oauth2/state.mjs.map +1 -0
  178. package/dist/oauth2/utils.d.mts +8 -0
  179. package/dist/oauth2/utils.mjs +31 -0
  180. package/dist/oauth2/utils.mjs.map +1 -0
  181. package/dist/plugins/access/access.d.mts +30 -0
  182. package/dist/plugins/access/access.mjs +46 -0
  183. package/dist/plugins/access/access.mjs.map +1 -0
  184. package/dist/plugins/access/index.d.mts +3 -0
  185. package/dist/plugins/access/index.mjs +3 -0
  186. package/dist/plugins/access/types.d.mts +17 -0
  187. package/dist/plugins/additional-fields/client.d.mts +96 -0
  188. package/dist/plugins/additional-fields/client.mjs +11 -0
  189. package/dist/plugins/additional-fields/client.mjs.map +1 -0
  190. package/dist/plugins/admin/access/index.d.mts +2 -0
  191. package/dist/plugins/admin/access/index.mjs +3 -0
  192. package/dist/plugins/admin/access/statement.d.mts +118 -0
  193. package/dist/plugins/admin/access/statement.mjs +53 -0
  194. package/dist/plugins/admin/access/statement.mjs.map +1 -0
  195. package/dist/plugins/admin/admin.d.mts +911 -0
  196. package/dist/plugins/admin/admin.mjs +95 -0
  197. package/dist/plugins/admin/admin.mjs.map +1 -0
  198. package/dist/plugins/admin/client.d.mts +76 -0
  199. package/dist/plugins/admin/client.mjs +36 -0
  200. package/dist/plugins/admin/client.mjs.map +1 -0
  201. package/dist/plugins/admin/error-codes.d.mts +29 -0
  202. package/dist/plugins/admin/error-codes.mjs +30 -0
  203. package/dist/plugins/admin/error-codes.mjs.map +1 -0
  204. package/dist/plugins/admin/has-permission.mjs +16 -0
  205. package/dist/plugins/admin/has-permission.mjs.map +1 -0
  206. package/dist/plugins/admin/index.d.mts +3 -0
  207. package/dist/plugins/admin/index.mjs +3 -0
  208. package/dist/plugins/admin/routes.mjs +841 -0
  209. package/dist/plugins/admin/routes.mjs.map +1 -0
  210. package/dist/plugins/admin/schema.d.mts +40 -0
  211. package/dist/plugins/admin/schema.mjs +34 -0
  212. package/dist/plugins/admin/schema.mjs.map +1 -0
  213. package/dist/plugins/admin/types.d.mts +89 -0
  214. package/dist/plugins/api-key/adapter.mjs +468 -0
  215. package/dist/plugins/api-key/adapter.mjs.map +1 -0
  216. package/dist/plugins/api-key/client.d.mts +46 -0
  217. package/dist/plugins/api-key/client.mjs +19 -0
  218. package/dist/plugins/api-key/client.mjs.map +1 -0
  219. package/dist/plugins/api-key/error-codes.d.mts +33 -0
  220. package/dist/plugins/api-key/error-codes.mjs +34 -0
  221. package/dist/plugins/api-key/error-codes.mjs.map +1 -0
  222. package/dist/plugins/api-key/index.d.mts +1251 -0
  223. package/dist/plugins/api-key/index.mjs +134 -0
  224. package/dist/plugins/api-key/index.mjs.map +1 -0
  225. package/dist/plugins/api-key/rate-limit.mjs +74 -0
  226. package/dist/plugins/api-key/rate-limit.mjs.map +1 -0
  227. package/dist/plugins/api-key/routes/create-api-key.mjs +252 -0
  228. package/dist/plugins/api-key/routes/create-api-key.mjs.map +1 -0
  229. package/dist/plugins/api-key/routes/delete-all-expired-api-keys.mjs +24 -0
  230. package/dist/plugins/api-key/routes/delete-all-expired-api-keys.mjs.map +1 -0
  231. package/dist/plugins/api-key/routes/delete-api-key.mjs +74 -0
  232. package/dist/plugins/api-key/routes/delete-api-key.mjs.map +1 -0
  233. package/dist/plugins/api-key/routes/get-api-key.mjs +158 -0
  234. package/dist/plugins/api-key/routes/get-api-key.mjs.map +1 -0
  235. package/dist/plugins/api-key/routes/index.mjs +71 -0
  236. package/dist/plugins/api-key/routes/index.mjs.map +1 -0
  237. package/dist/plugins/api-key/routes/list-api-keys.mjs +194 -0
  238. package/dist/plugins/api-key/routes/list-api-keys.mjs.map +1 -0
  239. package/dist/plugins/api-key/routes/update-api-key.mjs +248 -0
  240. package/dist/plugins/api-key/routes/update-api-key.mjs.map +1 -0
  241. package/dist/plugins/api-key/routes/verify-api-key.mjs +224 -0
  242. package/dist/plugins/api-key/routes/verify-api-key.mjs.map +1 -0
  243. package/dist/plugins/api-key/schema.d.mts +199 -0
  244. package/dist/plugins/api-key/schema.mjs +130 -0
  245. package/dist/plugins/api-key/schema.mjs.map +1 -0
  246. package/dist/plugins/api-key/types.d.mts +346 -0
  247. package/dist/plugins/bearer/index.d.mts +45 -0
  248. package/dist/plugins/bearer/index.mjs +66 -0
  249. package/dist/plugins/bearer/index.mjs.map +1 -0
  250. package/dist/plugins/captcha/constants.d.mts +10 -0
  251. package/dist/plugins/captcha/constants.mjs +22 -0
  252. package/dist/plugins/captcha/constants.mjs.map +1 -0
  253. package/dist/plugins/captcha/error-codes.mjs +16 -0
  254. package/dist/plugins/captcha/error-codes.mjs.map +1 -0
  255. package/dist/plugins/captcha/index.d.mts +21 -0
  256. package/dist/plugins/captcha/index.mjs +62 -0
  257. package/dist/plugins/captcha/index.mjs.map +1 -0
  258. package/dist/plugins/captcha/types.d.mts +28 -0
  259. package/dist/plugins/captcha/utils.mjs +11 -0
  260. package/dist/plugins/captcha/utils.mjs.map +1 -0
  261. package/dist/plugins/captcha/verify-handlers/captchafox.mjs +28 -0
  262. package/dist/plugins/captcha/verify-handlers/captchafox.mjs.map +1 -0
  263. package/dist/plugins/captcha/verify-handlers/cloudflare-turnstile.mjs +26 -0
  264. package/dist/plugins/captcha/verify-handlers/cloudflare-turnstile.mjs.map +1 -0
  265. package/dist/plugins/captcha/verify-handlers/google-recaptcha.mjs +30 -0
  266. package/dist/plugins/captcha/verify-handlers/google-recaptcha.mjs.map +1 -0
  267. package/dist/plugins/captcha/verify-handlers/h-captcha.mjs +28 -0
  268. package/dist/plugins/captcha/verify-handlers/h-captcha.mjs.map +1 -0
  269. package/dist/plugins/captcha/verify-handlers/index.mjs +6 -0
  270. package/dist/plugins/custom-session/client.d.mts +17 -0
  271. package/dist/plugins/custom-session/client.mjs +11 -0
  272. package/dist/plugins/custom-session/client.mjs.map +1 -0
  273. package/dist/plugins/custom-session/index.d.mts +72 -0
  274. package/dist/plugins/custom-session/index.mjs +78 -0
  275. package/dist/plugins/custom-session/index.mjs.map +1 -0
  276. package/dist/plugins/device-authorization/client.d.mts +17 -0
  277. package/dist/plugins/device-authorization/client.mjs +18 -0
  278. package/dist/plugins/device-authorization/client.mjs.map +1 -0
  279. package/dist/plugins/device-authorization/error-codes.mjs +21 -0
  280. package/dist/plugins/device-authorization/error-codes.mjs.map +1 -0
  281. package/dist/plugins/device-authorization/index.d.mts +424 -0
  282. package/dist/plugins/device-authorization/index.mjs +50 -0
  283. package/dist/plugins/device-authorization/index.mjs.map +1 -0
  284. package/dist/plugins/device-authorization/routes.mjs +510 -0
  285. package/dist/plugins/device-authorization/routes.mjs.map +1 -0
  286. package/dist/plugins/device-authorization/schema.mjs +57 -0
  287. package/dist/plugins/device-authorization/schema.mjs.map +1 -0
  288. package/dist/plugins/email-otp/client.d.mts +21 -0
  289. package/dist/plugins/email-otp/client.mjs +18 -0
  290. package/dist/plugins/email-otp/client.mjs.map +1 -0
  291. package/dist/plugins/email-otp/error-codes.d.mts +11 -0
  292. package/dist/plugins/email-otp/error-codes.mjs +12 -0
  293. package/dist/plugins/email-otp/error-codes.mjs.map +1 -0
  294. package/dist/plugins/email-otp/index.d.mts +428 -0
  295. package/dist/plugins/email-otp/index.mjs +130 -0
  296. package/dist/plugins/email-otp/index.mjs.map +1 -0
  297. package/dist/plugins/email-otp/otp-token.mjs +29 -0
  298. package/dist/plugins/email-otp/otp-token.mjs.map +1 -0
  299. package/dist/plugins/email-otp/routes.mjs +631 -0
  300. package/dist/plugins/email-otp/routes.mjs.map +1 -0
  301. package/dist/plugins/email-otp/types.d.mts +86 -0
  302. package/dist/plugins/email-otp/utils.mjs +17 -0
  303. package/dist/plugins/email-otp/utils.mjs.map +1 -0
  304. package/dist/plugins/generic-oauth/client.d.mts +33 -0
  305. package/dist/plugins/generic-oauth/client.mjs +14 -0
  306. package/dist/plugins/generic-oauth/client.mjs.map +1 -0
  307. package/dist/plugins/generic-oauth/error-codes.d.mts +16 -0
  308. package/dist/plugins/generic-oauth/error-codes.mjs +17 -0
  309. package/dist/plugins/generic-oauth/error-codes.mjs.map +1 -0
  310. package/dist/plugins/generic-oauth/index.d.mts +201 -0
  311. package/dist/plugins/generic-oauth/index.mjs +145 -0
  312. package/dist/plugins/generic-oauth/index.mjs.map +1 -0
  313. package/dist/plugins/generic-oauth/providers/auth0.d.mts +37 -0
  314. package/dist/plugins/generic-oauth/providers/auth0.mjs +62 -0
  315. package/dist/plugins/generic-oauth/providers/auth0.mjs.map +1 -0
  316. package/dist/plugins/generic-oauth/providers/gumroad.d.mts +32 -0
  317. package/dist/plugins/generic-oauth/providers/gumroad.mjs +60 -0
  318. package/dist/plugins/generic-oauth/providers/gumroad.mjs.map +1 -0
  319. package/dist/plugins/generic-oauth/providers/hubspot.d.mts +37 -0
  320. package/dist/plugins/generic-oauth/providers/hubspot.mjs +60 -0
  321. package/dist/plugins/generic-oauth/providers/hubspot.mjs.map +1 -0
  322. package/dist/plugins/generic-oauth/providers/index.d.mts +9 -0
  323. package/dist/plugins/generic-oauth/providers/index.mjs +11 -0
  324. package/dist/plugins/generic-oauth/providers/keycloak.d.mts +37 -0
  325. package/dist/plugins/generic-oauth/providers/keycloak.mjs +62 -0
  326. package/dist/plugins/generic-oauth/providers/keycloak.mjs.map +1 -0
  327. package/dist/plugins/generic-oauth/providers/line.d.mts +55 -0
  328. package/dist/plugins/generic-oauth/providers/line.mjs +91 -0
  329. package/dist/plugins/generic-oauth/providers/line.mjs.map +1 -0
  330. package/dist/plugins/generic-oauth/providers/microsoft-entra-id.d.mts +37 -0
  331. package/dist/plugins/generic-oauth/providers/microsoft-entra-id.mjs +66 -0
  332. package/dist/plugins/generic-oauth/providers/microsoft-entra-id.mjs.map +1 -0
  333. package/dist/plugins/generic-oauth/providers/okta.d.mts +37 -0
  334. package/dist/plugins/generic-oauth/providers/okta.mjs +62 -0
  335. package/dist/plugins/generic-oauth/providers/okta.mjs.map +1 -0
  336. package/dist/plugins/generic-oauth/providers/patreon.d.mts +30 -0
  337. package/dist/plugins/generic-oauth/providers/patreon.mjs +59 -0
  338. package/dist/plugins/generic-oauth/providers/patreon.mjs.map +1 -0
  339. package/dist/plugins/generic-oauth/providers/slack.d.mts +30 -0
  340. package/dist/plugins/generic-oauth/providers/slack.mjs +61 -0
  341. package/dist/plugins/generic-oauth/providers/slack.mjs.map +1 -0
  342. package/dist/plugins/generic-oauth/routes.mjs +411 -0
  343. package/dist/plugins/generic-oauth/routes.mjs.map +1 -0
  344. package/dist/plugins/generic-oauth/types.d.mts +159 -0
  345. package/dist/plugins/haveibeenpwned/index.d.mts +46 -0
  346. package/dist/plugins/haveibeenpwned/index.mjs +57 -0
  347. package/dist/plugins/haveibeenpwned/index.mjs.map +1 -0
  348. package/dist/plugins/index.d.mts +65 -0
  349. package/dist/plugins/index.mjs +48 -0
  350. package/dist/plugins/jwt/adapter.mjs +27 -0
  351. package/dist/plugins/jwt/adapter.mjs.map +1 -0
  352. package/dist/plugins/jwt/client.d.mts +40 -0
  353. package/dist/plugins/jwt/client.mjs +19 -0
  354. package/dist/plugins/jwt/client.mjs.map +1 -0
  355. package/dist/plugins/jwt/index.d.mts +224 -0
  356. package/dist/plugins/jwt/index.mjs +202 -0
  357. package/dist/plugins/jwt/index.mjs.map +1 -0
  358. package/dist/plugins/jwt/schema.d.mts +26 -0
  359. package/dist/plugins/jwt/schema.mjs +23 -0
  360. package/dist/plugins/jwt/schema.mjs.map +1 -0
  361. package/dist/plugins/jwt/sign.d.mts +57 -0
  362. package/dist/plugins/jwt/sign.mjs +66 -0
  363. package/dist/plugins/jwt/sign.mjs.map +1 -0
  364. package/dist/plugins/jwt/types.d.mts +194 -0
  365. package/dist/plugins/jwt/utils.d.mts +42 -0
  366. package/dist/plugins/jwt/utils.mjs +64 -0
  367. package/dist/plugins/jwt/utils.mjs.map +1 -0
  368. package/dist/plugins/jwt/verify.d.mts +12 -0
  369. package/dist/plugins/jwt/verify.mjs +46 -0
  370. package/dist/plugins/jwt/verify.mjs.map +1 -0
  371. package/dist/plugins/last-login-method/client.d.mts +38 -0
  372. package/dist/plugins/last-login-method/client.mjs +32 -0
  373. package/dist/plugins/last-login-method/client.mjs.map +1 -0
  374. package/dist/plugins/last-login-method/index.d.mts +118 -0
  375. package/dist/plugins/last-login-method/index.mjs +76 -0
  376. package/dist/plugins/last-login-method/index.mjs.map +1 -0
  377. package/dist/plugins/magic-link/client.d.mts +10 -0
  378. package/dist/plugins/magic-link/client.mjs +11 -0
  379. package/dist/plugins/magic-link/client.mjs.map +1 -0
  380. package/dist/plugins/magic-link/index.d.mts +193 -0
  381. package/dist/plugins/magic-link/index.mjs +177 -0
  382. package/dist/plugins/magic-link/index.mjs.map +1 -0
  383. package/dist/plugins/magic-link/utils.mjs +12 -0
  384. package/dist/plugins/magic-link/utils.mjs.map +1 -0
  385. package/dist/plugins/mcp/authorize.mjs +133 -0
  386. package/dist/plugins/mcp/authorize.mjs.map +1 -0
  387. package/dist/plugins/mcp/index.d.mts +458 -0
  388. package/dist/plugins/mcp/index.mjs +717 -0
  389. package/dist/plugins/mcp/index.mjs.map +1 -0
  390. package/dist/plugins/multi-session/client.d.mts +19 -0
  391. package/dist/plugins/multi-session/client.mjs +20 -0
  392. package/dist/plugins/multi-session/client.mjs.map +1 -0
  393. package/dist/plugins/multi-session/error-codes.d.mts +9 -0
  394. package/dist/plugins/multi-session/error-codes.mjs +8 -0
  395. package/dist/plugins/multi-session/error-codes.mjs.map +1 -0
  396. package/dist/plugins/multi-session/index.d.mts +235 -0
  397. package/dist/plugins/multi-session/index.mjs +172 -0
  398. package/dist/plugins/multi-session/index.mjs.map +1 -0
  399. package/dist/plugins/oauth-proxy/index.d.mts +97 -0
  400. package/dist/plugins/oauth-proxy/index.mjs +305 -0
  401. package/dist/plugins/oauth-proxy/index.mjs.map +1 -0
  402. package/dist/plugins/oauth-proxy/utils.mjs +51 -0
  403. package/dist/plugins/oauth-proxy/utils.mjs.map +1 -0
  404. package/dist/plugins/oidc-provider/authorize.mjs +194 -0
  405. package/dist/plugins/oidc-provider/authorize.mjs.map +1 -0
  406. package/dist/plugins/oidc-provider/client.d.mts +12 -0
  407. package/dist/plugins/oidc-provider/client.mjs +11 -0
  408. package/dist/plugins/oidc-provider/client.mjs.map +1 -0
  409. package/dist/plugins/oidc-provider/error.mjs +17 -0
  410. package/dist/plugins/oidc-provider/error.mjs.map +1 -0
  411. package/dist/plugins/oidc-provider/index.d.mts +702 -0
  412. package/dist/plugins/oidc-provider/index.mjs +1093 -0
  413. package/dist/plugins/oidc-provider/index.mjs.map +1 -0
  414. package/dist/plugins/oidc-provider/schema.d.mts +160 -0
  415. package/dist/plugins/oidc-provider/schema.mjs +132 -0
  416. package/dist/plugins/oidc-provider/schema.mjs.map +1 -0
  417. package/dist/plugins/oidc-provider/types.d.mts +517 -0
  418. package/dist/plugins/oidc-provider/utils/prompt.mjs +19 -0
  419. package/dist/plugins/oidc-provider/utils/prompt.mjs.map +1 -0
  420. package/dist/plugins/oidc-provider/utils.mjs +15 -0
  421. package/dist/plugins/oidc-provider/utils.mjs.map +1 -0
  422. package/dist/plugins/one-tap/client.d.mts +174 -0
  423. package/dist/plugins/one-tap/client.mjs +188 -0
  424. package/dist/plugins/one-tap/client.mjs.map +1 -0
  425. package/dist/plugins/one-tap/index.d.mts +83 -0
  426. package/dist/plugins/one-tap/index.mjs +95 -0
  427. package/dist/plugins/one-tap/index.mjs.map +1 -0
  428. package/dist/plugins/one-time-token/client.d.mts +10 -0
  429. package/dist/plugins/one-time-token/client.mjs +11 -0
  430. package/dist/plugins/one-time-token/client.mjs.map +1 -0
  431. package/dist/plugins/one-time-token/index.d.mts +133 -0
  432. package/dist/plugins/one-time-token/index.mjs +82 -0
  433. package/dist/plugins/one-time-token/index.mjs.map +1 -0
  434. package/dist/plugins/one-time-token/utils.mjs +12 -0
  435. package/dist/plugins/one-time-token/utils.mjs.map +1 -0
  436. package/dist/plugins/open-api/generator.d.mts +115 -0
  437. package/dist/plugins/open-api/generator.mjs +315 -0
  438. package/dist/plugins/open-api/generator.mjs.map +1 -0
  439. package/dist/plugins/open-api/index.d.mts +97 -0
  440. package/dist/plugins/open-api/index.mjs +67 -0
  441. package/dist/plugins/open-api/index.mjs.map +1 -0
  442. package/dist/plugins/open-api/logo.mjs +15 -0
  443. package/dist/plugins/open-api/logo.mjs.map +1 -0
  444. package/dist/plugins/organization/access/index.d.mts +2 -0
  445. package/dist/plugins/organization/access/index.mjs +3 -0
  446. package/dist/plugins/organization/access/statement.d.mts +249 -0
  447. package/dist/plugins/organization/access/statement.mjs +81 -0
  448. package/dist/plugins/organization/access/statement.mjs.map +1 -0
  449. package/dist/plugins/organization/adapter.d.mts +792 -0
  450. package/dist/plugins/organization/adapter.mjs +624 -0
  451. package/dist/plugins/organization/adapter.mjs.map +1 -0
  452. package/dist/plugins/organization/call.mjs +19 -0
  453. package/dist/plugins/organization/call.mjs.map +1 -0
  454. package/dist/plugins/organization/client.d.mts +372 -0
  455. package/dist/plugins/organization/client.mjs +95 -0
  456. package/dist/plugins/organization/client.mjs.map +1 -0
  457. package/dist/plugins/organization/error-codes.d.mts +65 -0
  458. package/dist/plugins/organization/error-codes.mjs +66 -0
  459. package/dist/plugins/organization/error-codes.mjs.map +1 -0
  460. package/dist/plugins/organization/has-permission.mjs +35 -0
  461. package/dist/plugins/organization/has-permission.mjs.map +1 -0
  462. package/dist/plugins/organization/index.d.mts +5 -0
  463. package/dist/plugins/organization/index.mjs +4 -0
  464. package/dist/plugins/organization/organization.d.mts +394 -0
  465. package/dist/plugins/organization/organization.mjs +428 -0
  466. package/dist/plugins/organization/organization.mjs.map +1 -0
  467. package/dist/plugins/organization/permission.d.mts +17 -0
  468. package/dist/plugins/organization/permission.mjs +16 -0
  469. package/dist/plugins/organization/permission.mjs.map +1 -0
  470. package/dist/plugins/organization/routes/crud-access-control.d.mts +394 -0
  471. package/dist/plugins/organization/routes/crud-access-control.mjs +678 -0
  472. package/dist/plugins/organization/routes/crud-access-control.mjs.map +1 -0
  473. package/dist/plugins/organization/routes/crud-invites.d.mts +1031 -0
  474. package/dist/plugins/organization/routes/crud-invites.mjs +551 -0
  475. package/dist/plugins/organization/routes/crud-invites.mjs.map +1 -0
  476. package/dist/plugins/organization/routes/crud-members.d.mts +940 -0
  477. package/dist/plugins/organization/routes/crud-members.mjs +466 -0
  478. package/dist/plugins/organization/routes/crud-members.mjs.map +1 -0
  479. package/dist/plugins/organization/routes/crud-org.d.mts +708 -0
  480. package/dist/plugins/organization/routes/crud-org.mjs +423 -0
  481. package/dist/plugins/organization/routes/crud-org.mjs.map +1 -0
  482. package/dist/plugins/organization/routes/crud-team.d.mts +1071 -0
  483. package/dist/plugins/organization/routes/crud-team.mjs +676 -0
  484. package/dist/plugins/organization/routes/crud-team.mjs.map +1 -0
  485. package/dist/plugins/organization/schema.d.mts +376 -0
  486. package/dist/plugins/organization/schema.mjs +68 -0
  487. package/dist/plugins/organization/schema.mjs.map +1 -0
  488. package/dist/plugins/organization/types.d.mts +677 -0
  489. package/dist/plugins/phone-number/client.d.mts +31 -0
  490. package/dist/plugins/phone-number/client.mjs +20 -0
  491. package/dist/plugins/phone-number/client.mjs.map +1 -0
  492. package/dist/plugins/phone-number/error-codes.d.mts +20 -0
  493. package/dist/plugins/phone-number/error-codes.mjs +21 -0
  494. package/dist/plugins/phone-number/error-codes.mjs.map +1 -0
  495. package/dist/plugins/phone-number/index.d.mts +318 -0
  496. package/dist/plugins/phone-number/index.mjs +49 -0
  497. package/dist/plugins/phone-number/index.mjs.map +1 -0
  498. package/dist/plugins/phone-number/routes.mjs +472 -0
  499. package/dist/plugins/phone-number/routes.mjs.map +1 -0
  500. package/dist/plugins/phone-number/schema.d.mts +23 -0
  501. package/dist/plugins/phone-number/schema.mjs +20 -0
  502. package/dist/plugins/phone-number/schema.mjs.map +1 -0
  503. package/dist/plugins/phone-number/types.d.mts +118 -0
  504. package/dist/plugins/two-factor/backup-codes/index.d.mts +279 -0
  505. package/dist/plugins/two-factor/backup-codes/index.mjs +277 -0
  506. package/dist/plugins/two-factor/backup-codes/index.mjs.map +1 -0
  507. package/dist/plugins/two-factor/client.d.mts +55 -0
  508. package/dist/plugins/two-factor/client.mjs +37 -0
  509. package/dist/plugins/two-factor/client.mjs.map +1 -0
  510. package/dist/plugins/two-factor/constant.mjs +8 -0
  511. package/dist/plugins/two-factor/constant.mjs.map +1 -0
  512. package/dist/plugins/two-factor/error-code.d.mts +17 -0
  513. package/dist/plugins/two-factor/error-code.mjs +18 -0
  514. package/dist/plugins/two-factor/error-code.mjs.map +1 -0
  515. package/dist/plugins/two-factor/index.d.mts +670 -0
  516. package/dist/plugins/two-factor/index.mjs +228 -0
  517. package/dist/plugins/two-factor/index.mjs.map +1 -0
  518. package/dist/plugins/two-factor/otp/index.d.mts +216 -0
  519. package/dist/plugins/two-factor/otp/index.mjs +199 -0
  520. package/dist/plugins/two-factor/otp/index.mjs.map +1 -0
  521. package/dist/plugins/two-factor/schema.d.mts +41 -0
  522. package/dist/plugins/two-factor/schema.mjs +36 -0
  523. package/dist/plugins/two-factor/schema.mjs.map +1 -0
  524. package/dist/plugins/two-factor/totp/index.d.mts +210 -0
  525. package/dist/plugins/two-factor/totp/index.mjs +157 -0
  526. package/dist/plugins/two-factor/totp/index.mjs.map +1 -0
  527. package/dist/plugins/two-factor/types.d.mts +73 -0
  528. package/dist/plugins/two-factor/utils.mjs +12 -0
  529. package/dist/plugins/two-factor/utils.mjs.map +1 -0
  530. package/dist/plugins/two-factor/verify-two-factor.mjs +85 -0
  531. package/dist/plugins/two-factor/verify-two-factor.mjs.map +1 -0
  532. package/dist/plugins/username/client.d.mts +26 -0
  533. package/dist/plugins/username/client.mjs +18 -0
  534. package/dist/plugins/username/client.mjs.map +1 -0
  535. package/dist/plugins/username/error-codes.d.mts +16 -0
  536. package/dist/plugins/username/error-codes.mjs +17 -0
  537. package/dist/plugins/username/error-codes.mjs.map +1 -0
  538. package/dist/plugins/username/index.d.mts +251 -0
  539. package/dist/plugins/username/index.mjs +234 -0
  540. package/dist/plugins/username/index.mjs.map +1 -0
  541. package/dist/plugins/username/schema.d.mts +33 -0
  542. package/dist/plugins/username/schema.mjs +26 -0
  543. package/dist/plugins/username/schema.mjs.map +1 -0
  544. package/dist/providers/index.d.mts +1 -0
  545. package/dist/providers/index.mjs +3 -0
  546. package/dist/state.d.mts +42 -0
  547. package/dist/state.mjs +107 -0
  548. package/dist/state.mjs.map +1 -0
  549. package/dist/types/adapter.d.mts +2 -0
  550. package/dist/types/api.d.mts +29 -0
  551. package/dist/types/auth.d.mts +29 -0
  552. package/dist/types/helper.d.mts +10 -0
  553. package/dist/types/index.d.mts +11 -0
  554. package/dist/types/index.mjs +1 -0
  555. package/dist/types/models.d.mts +11 -0
  556. package/dist/types/plugins.d.mts +20 -0
  557. package/dist/utils/boolean.mjs +8 -0
  558. package/dist/utils/boolean.mjs.map +1 -0
  559. package/dist/utils/constants.mjs +6 -0
  560. package/dist/utils/constants.mjs.map +1 -0
  561. package/dist/utils/date.mjs +8 -0
  562. package/dist/utils/date.mjs.map +1 -0
  563. package/dist/utils/get-request-ip.d.mts +7 -0
  564. package/dist/utils/get-request-ip.mjs +23 -0
  565. package/dist/utils/get-request-ip.mjs.map +1 -0
  566. package/dist/utils/hide-metadata.d.mts +7 -0
  567. package/dist/utils/hide-metadata.mjs +6 -0
  568. package/dist/utils/hide-metadata.mjs.map +1 -0
  569. package/dist/utils/index.d.mts +4 -0
  570. package/dist/utils/index.mjs +6 -0
  571. package/dist/utils/is-api-error.d.mts +7 -0
  572. package/dist/utils/is-api-error.mjs +11 -0
  573. package/dist/utils/is-api-error.mjs.map +1 -0
  574. package/dist/utils/is-atom.mjs +8 -0
  575. package/dist/utils/is-atom.mjs.map +1 -0
  576. package/dist/utils/is-promise.mjs +8 -0
  577. package/dist/utils/is-promise.mjs.map +1 -0
  578. package/dist/utils/middleware-response.mjs +9 -0
  579. package/dist/utils/middleware-response.mjs.map +1 -0
  580. package/dist/utils/password.mjs +26 -0
  581. package/dist/utils/password.mjs.map +1 -0
  582. package/dist/utils/plugin-helper.mjs +17 -0
  583. package/dist/utils/plugin-helper.mjs.map +1 -0
  584. package/dist/utils/shim.mjs +24 -0
  585. package/dist/utils/shim.mjs.map +1 -0
  586. package/dist/utils/time.d.mts +49 -0
  587. package/dist/utils/time.mjs +100 -0
  588. package/dist/utils/time.mjs.map +1 -0
  589. package/dist/utils/url.d.mts +8 -0
  590. package/dist/utils/url.mjs +92 -0
  591. package/dist/utils/url.mjs.map +1 -0
  592. package/dist/utils/wildcard.mjs +108 -0
  593. package/dist/utils/wildcard.mjs.map +1 -0
  594. package/package.json +428 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../../../../src/plugins/two-factor/totp/index.ts"],"sourcesContent":["import { createAuthEndpoint } from \"@better-auth/core/api\";\nimport { APIError, BASE_ERROR_CODES } from \"@better-auth/core/error\";\nimport { createOTP } from \"@better-auth/utils/otp\";\nimport * as z from \"zod\";\nimport { sessionMiddleware } from \"../../../api\";\nimport { setSessionCookie } from \"../../../cookies\";\nimport { symmetricDecrypt } from \"../../../crypto\";\nimport type { BackupCodeOptions } from \"../backup-codes\";\nimport { TWO_FACTOR_ERROR_CODES } from \"../error-code\";\nimport type {\n\tTwoFactorProvider,\n\tTwoFactorTable,\n\tUserWithTwoFactor,\n} from \"../types\";\nimport { verifyTwoFactor } from \"../verify-two-factor\";\n\nexport type TOTPOptions = {\n\t/**\n\t * Issuer\n\t */\n\tissuer?: string | undefined;\n\t/**\n\t * How many digits the otp to be\n\t *\n\t * @default 6\n\t */\n\tdigits?: (6 | 8) | undefined;\n\t/**\n\t * Period for otp in seconds.\n\t * @default 30\n\t */\n\tperiod?: number | undefined;\n\t/**\n\t * Backup codes configuration\n\t */\n\tbackupCodes?: BackupCodeOptions | undefined;\n\t/**\n\t * Disable totp\n\t */\n\tdisable?: boolean | undefined;\n};\n\nconst generateTOTPBodySchema = z.object({\n\tsecret: z.string().meta({\n\t\tdescription: \"The secret to generate the TOTP code\",\n\t}),\n});\n\nconst getTOTPURIBodySchema = z.object({\n\tpassword: z.string().meta({\n\t\tdescription: \"User password\",\n\t}),\n});\n\nconst verifyTOTPBodySchema = z.object({\n\tcode: z.string().meta({\n\t\tdescription: 'The otp code to verify. Eg: \"012345\"',\n\t}),\n\t/**\n\t * if true, the device will be trusted\n\t * for 30 days. It'll be refreshed on\n\t * every sign in request within this time.\n\t */\n\ttrustDevice: z\n\t\t.boolean()\n\t\t.meta({\n\t\t\tdescription:\n\t\t\t\t\"If true, the device will be trusted for 30 days. It'll be refreshed on every sign in request within this time. Eg: true\",\n\t\t})\n\t\t.optional(),\n});\n\nexport const totp2fa = (options?: TOTPOptions | undefined) => {\n\tconst opts = {\n\t\t...options,\n\t\tdigits: options?.digits || 6,\n\t\tperiod: options?.period || 30,\n\t};\n\n\tconst twoFactorTable = \"twoFactor\";\n\n\tconst generateTOTP = createAuthEndpoint(\n\t\t{\n\t\t\tmethod: \"POST\",\n\t\t\tbody: generateTOTPBodySchema,\n\t\t\tmetadata: {\n\t\t\t\topenapi: {\n\t\t\t\t\tsummary: \"Generate TOTP code\",\n\t\t\t\t\tdescription: \"Use this endpoint to generate a TOTP code\",\n\t\t\t\t\tresponses: {\n\t\t\t\t\t\t200: {\n\t\t\t\t\t\t\tdescription: \"Successful response\",\n\t\t\t\t\t\t\tcontent: {\n\t\t\t\t\t\t\t\t\"application/json\": {\n\t\t\t\t\t\t\t\t\tschema: {\n\t\t\t\t\t\t\t\t\t\ttype: \"object\",\n\t\t\t\t\t\t\t\t\t\tproperties: {\n\t\t\t\t\t\t\t\t\t\t\tcode: {\n\t\t\t\t\t\t\t\t\t\t\t\ttype: \"string\",\n\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t},\n\t\tasync (ctx) => {\n\t\t\tif (options?.disable) {\n\t\t\t\tctx.context.logger.error(\n\t\t\t\t\t\"totp isn't configured. please pass totp option on two factor plugin to enable totp\",\n\t\t\t\t);\n\t\t\t\tthrow APIError.from(\"BAD_REQUEST\", {\n\t\t\t\t\tmessage: \"totp isn't configured\",\n\t\t\t\t\tcode: \"TOTP_NOT_CONFIGURED\",\n\t\t\t\t});\n\t\t\t}\n\t\t\tconst code = await createOTP(ctx.body.secret, {\n\t\t\t\tperiod: opts.period,\n\t\t\t\tdigits: opts.digits,\n\t\t\t}).totp();\n\t\t\treturn { code };\n\t\t},\n\t);\n\n\tconst getTOTPURI = createAuthEndpoint(\n\t\t\"/two-factor/get-totp-uri\",\n\t\t{\n\t\t\tmethod: \"POST\",\n\t\t\tuse: [sessionMiddleware],\n\t\t\tbody: getTOTPURIBodySchema,\n\t\t\tmetadata: {\n\t\t\t\topenapi: {\n\t\t\t\t\tsummary: \"Get TOTP URI\",\n\t\t\t\t\tdescription: \"Use this endpoint to get the TOTP URI\",\n\t\t\t\t\tresponses: {\n\t\t\t\t\t\t200: {\n\t\t\t\t\t\t\tdescription: \"Successful response\",\n\t\t\t\t\t\t\tcontent: {\n\t\t\t\t\t\t\t\t\"application/json\": {\n\t\t\t\t\t\t\t\t\tschema: {\n\t\t\t\t\t\t\t\t\t\ttype: \"object\",\n\t\t\t\t\t\t\t\t\t\tproperties: {\n\t\t\t\t\t\t\t\t\t\t\ttotpURI: {\n\t\t\t\t\t\t\t\t\t\t\t\ttype: \"string\",\n\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t},\n\t\tasync (ctx) => {\n\t\t\tif (options?.disable) {\n\t\t\t\tctx.context.logger.error(\n\t\t\t\t\t\"totp isn't configured. please pass totp option on two factor plugin to enable totp\",\n\t\t\t\t);\n\t\t\t\tthrow APIError.from(\"BAD_REQUEST\", {\n\t\t\t\t\tmessage: \"totp isn't configured\",\n\t\t\t\t\tcode: \"TOTP_NOT_CONFIGURED\",\n\t\t\t\t});\n\t\t\t}\n\t\t\tconst user = ctx.context.session.user as UserWithTwoFactor;\n\t\t\tconst twoFactor = await ctx.context.adapter.findOne<TwoFactorTable>({\n\t\t\t\tmodel: twoFactorTable,\n\t\t\t\twhere: [\n\t\t\t\t\t{\n\t\t\t\t\t\tfield: \"userId\",\n\t\t\t\t\t\tvalue: user.id,\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t});\n\t\t\tif (!twoFactor) {\n\t\t\t\tthrow APIError.from(\n\t\t\t\t\t\"BAD_REQUEST\",\n\t\t\t\t\tTWO_FACTOR_ERROR_CODES.TOTP_NOT_ENABLED,\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst secret = await symmetricDecrypt({\n\t\t\t\tkey: ctx.context.secret,\n\t\t\t\tdata: twoFactor.secret,\n\t\t\t});\n\t\t\tawait ctx.context.password.checkPassword(user.id, ctx);\n\t\t\tconst totpURI = createOTP(secret, {\n\t\t\t\tdigits: opts.digits,\n\t\t\t\tperiod: opts.period,\n\t\t\t}).url(options?.issuer || ctx.context.appName, user.email);\n\t\t\treturn {\n\t\t\t\ttotpURI,\n\t\t\t};\n\t\t},\n\t);\n\n\tconst verifyTOTP = createAuthEndpoint(\n\t\t\"/two-factor/verify-totp\",\n\t\t{\n\t\t\tmethod: \"POST\",\n\t\t\tbody: verifyTOTPBodySchema,\n\t\t\tmetadata: {\n\t\t\t\topenapi: {\n\t\t\t\t\tsummary: \"Verify two factor TOTP\",\n\t\t\t\t\tdescription: \"Verify two factor TOTP\",\n\t\t\t\t\tresponses: {\n\t\t\t\t\t\t200: {\n\t\t\t\t\t\t\tdescription: \"Successful response\",\n\t\t\t\t\t\t\tcontent: {\n\t\t\t\t\t\t\t\t\"application/json\": {\n\t\t\t\t\t\t\t\t\tschema: {\n\t\t\t\t\t\t\t\t\t\ttype: \"object\",\n\t\t\t\t\t\t\t\t\t\tproperties: {\n\t\t\t\t\t\t\t\t\t\t\tstatus: {\n\t\t\t\t\t\t\t\t\t\t\t\ttype: \"boolean\",\n\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t},\n\t\tasync (ctx) => {\n\t\t\tif (options?.disable) {\n\t\t\t\tctx.context.logger.error(\n\t\t\t\t\t\"totp isn't configured. please pass totp option on two factor plugin to enable totp\",\n\t\t\t\t);\n\t\t\t\tthrow APIError.from(\"BAD_REQUEST\", {\n\t\t\t\t\tmessage: \"totp isn't configured\",\n\t\t\t\t\tcode: \"TOTP_NOT_CONFIGURED\",\n\t\t\t\t});\n\t\t\t}\n\t\t\tconst { session, valid, invalid } = await verifyTwoFactor(ctx);\n\t\t\tconst user = session.user as UserWithTwoFactor;\n\t\t\tconst twoFactor = await ctx.context.adapter.findOne<TwoFactorTable>({\n\t\t\t\tmodel: twoFactorTable,\n\t\t\t\twhere: [\n\t\t\t\t\t{\n\t\t\t\t\t\tfield: \"userId\",\n\t\t\t\t\t\tvalue: user.id,\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t});\n\n\t\t\tif (!twoFactor) {\n\t\t\t\tthrow APIError.from(\n\t\t\t\t\t\"BAD_REQUEST\",\n\t\t\t\t\tTWO_FACTOR_ERROR_CODES.TOTP_NOT_ENABLED,\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst decrypted = await symmetricDecrypt({\n\t\t\t\tkey: ctx.context.secret,\n\t\t\t\tdata: twoFactor.secret,\n\t\t\t});\n\t\t\tconst status = await createOTP(decrypted, {\n\t\t\t\tperiod: opts.period,\n\t\t\t\tdigits: opts.digits,\n\t\t\t}).verify(ctx.body.code);\n\t\t\tif (!status) {\n\t\t\t\treturn invalid(\"INVALID_CODE\");\n\t\t\t}\n\n\t\t\tif (!user.twoFactorEnabled) {\n\t\t\t\tif (!session.session) {\n\t\t\t\t\tthrow APIError.from(\n\t\t\t\t\t\t\"BAD_REQUEST\",\n\t\t\t\t\t\tBASE_ERROR_CODES.FAILED_TO_CREATE_SESSION,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tconst updatedUser = await ctx.context.internalAdapter.updateUser(\n\t\t\t\t\tuser.id,\n\t\t\t\t\t{\n\t\t\t\t\t\ttwoFactorEnabled: true,\n\t\t\t\t\t},\n\t\t\t\t);\n\t\t\t\tconst newSession = await ctx.context.internalAdapter\n\t\t\t\t\t.createSession(user.id, false, session.session)\n\t\t\t\t\t.catch((e) => {\n\t\t\t\t\t\tthrow e;\n\t\t\t\t\t});\n\n\t\t\t\tawait ctx.context.internalAdapter.deleteSession(session.session.token);\n\t\t\t\tawait setSessionCookie(ctx, {\n\t\t\t\t\tsession: newSession,\n\t\t\t\t\tuser: updatedUser,\n\t\t\t\t});\n\t\t\t}\n\t\t\treturn valid(ctx);\n\t\t},\n\t);\n\n\treturn {\n\t\tid: \"totp\",\n\t\tendpoints: {\n\t\t\t/**\n\t\t\t * ### Endpoint\n\t\t\t *\n\t\t\t * POST `/totp/generate`\n\t\t\t *\n\t\t\t * ### API Methods\n\t\t\t *\n\t\t\t * **server:**\n\t\t\t * `auth.api.generateTOTP`\n\t\t\t *\n\t\t\t * @see [Read our docs to learn more.](https://better-auth.com/docs/plugins/2fa#totp)\n\t\t\t */\n\t\t\tgenerateTOTP: generateTOTP,\n\t\t\t/**\n\t\t\t * ### Endpoint\n\t\t\t *\n\t\t\t * POST `/two-factor/get-totp-uri`\n\t\t\t *\n\t\t\t * ### API Methods\n\t\t\t *\n\t\t\t * **server:**\n\t\t\t * `auth.api.getTOTPURI`\n\t\t\t *\n\t\t\t * **client:**\n\t\t\t * `authClient.twoFactor.getTotpUri`\n\t\t\t *\n\t\t\t * @see [Read our docs to learn more.](https://better-auth.com/docs/plugins/2fa#getting-totp-uri)\n\t\t\t */\n\t\t\tgetTOTPURI: getTOTPURI,\n\t\t\t/**\n\t\t\t * ### Endpoint\n\t\t\t *\n\t\t\t * POST `/two-factor/verify-totp`\n\t\t\t *\n\t\t\t * ### API Methods\n\t\t\t *\n\t\t\t * **server:**\n\t\t\t * `auth.api.verifyTOTP`\n\t\t\t *\n\t\t\t * **client:**\n\t\t\t * `authClient.twoFactor.verifyTotp`\n\t\t\t *\n\t\t\t * @see [Read our docs to learn more.](https://better-auth.com/docs/plugins/2fa#verifying-totp)\n\t\t\t */\n\t\t\tverifyTOTP,\n\t\t},\n\t} satisfies TwoFactorProvider;\n};\n"],"mappings":";;;;;;;;;;;;AA0CA,MAAM,yBAAyB,EAAE,OAAO,EACvC,QAAQ,EAAE,QAAQ,CAAC,KAAK,EACvB,aAAa,wCACb,CAAC,EACF,CAAC;AAEF,MAAM,uBAAuB,EAAE,OAAO,EACrC,UAAU,EAAE,QAAQ,CAAC,KAAK,EACzB,aAAa,iBACb,CAAC,EACF,CAAC;AAEF,MAAM,uBAAuB,EAAE,OAAO;CACrC,MAAM,EAAE,QAAQ,CAAC,KAAK,EACrB,aAAa,0CACb,CAAC;CAMF,aAAa,EACX,SAAS,CACT,KAAK,EACL,aACC,2HACD,CAAC,CACD,UAAU;CACZ,CAAC;AAEF,MAAa,WAAW,YAAsC;CAC7D,MAAM,OAAO;EACZ,GAAG;EACH,QAAQ,SAAS,UAAU;EAC3B,QAAQ,SAAS,UAAU;EAC3B;CAED,MAAM,iBAAiB;AAyNvB,QAAO;EACN,IAAI;EACJ,WAAW;GAaV,cAtOmB,mBACpB;IACC,QAAQ;IACR,MAAM;IACN,UAAU,EACT,SAAS;KACR,SAAS;KACT,aAAa;KACb,WAAW,EACV,KAAK;MACJ,aAAa;MACb,SAAS,EACR,oBAAoB,EACnB,QAAQ;OACP,MAAM;OACN,YAAY,EACX,MAAM,EACL,MAAM,UACN,EACD;OACD,EACD,EACD;MACD,EACD;KACD,EACD;IACD,EACD,OAAO,QAAQ;AACd,QAAI,SAAS,SAAS;AACrB,SAAI,QAAQ,OAAO,MAClB,qFACA;AACD,WAAM,SAAS,KAAK,eAAe;MAClC,SAAS;MACT,MAAM;MACN,CAAC;;AAMH,WAAO,EAAE,MAJI,MAAM,UAAU,IAAI,KAAK,QAAQ;KAC7C,QAAQ,KAAK;KACb,QAAQ,KAAK;KACb,CAAC,CAAC,MAAM,EACM;KAEhB;GA0MC,YAxMiB,mBAClB,4BACA;IACC,QAAQ;IACR,KAAK,CAAC,kBAAkB;IACxB,MAAM;IACN,UAAU,EACT,SAAS;KACR,SAAS;KACT,aAAa;KACb,WAAW,EACV,KAAK;MACJ,aAAa;MACb,SAAS,EACR,oBAAoB,EACnB,QAAQ;OACP,MAAM;OACN,YAAY,EACX,SAAS,EACR,MAAM,UACN,EACD;OACD,EACD,EACD;MACD,EACD;KACD,EACD;IACD,EACD,OAAO,QAAQ;AACd,QAAI,SAAS,SAAS;AACrB,SAAI,QAAQ,OAAO,MAClB,qFACA;AACD,WAAM,SAAS,KAAK,eAAe;MAClC,SAAS;MACT,MAAM;MACN,CAAC;;IAEH,MAAM,OAAO,IAAI,QAAQ,QAAQ;IACjC,MAAM,YAAY,MAAM,IAAI,QAAQ,QAAQ,QAAwB;KACnE,OAAO;KACP,OAAO,CACN;MACC,OAAO;MACP,OAAO,KAAK;MACZ,CACD;KACD,CAAC;AACF,QAAI,CAAC,UACJ,OAAM,SAAS,KACd,eACA,uBAAuB,iBACvB;IAEF,MAAM,SAAS,MAAM,iBAAiB;KACrC,KAAK,IAAI,QAAQ;KACjB,MAAM,UAAU;KAChB,CAAC;AACF,UAAM,IAAI,QAAQ,SAAS,cAAc,KAAK,IAAI,IAAI;AAKtD,WAAO,EACN,SALe,UAAU,QAAQ;KACjC,QAAQ,KAAK;KACb,QAAQ,KAAK;KACb,CAAC,CAAC,IAAI,SAAS,UAAU,IAAI,QAAQ,SAAS,KAAK,MAAM,EAGzD;KAEF;GAmJC,YAjJiB,mBAClB,2BACA;IACC,QAAQ;IACR,MAAM;IACN,UAAU,EACT,SAAS;KACR,SAAS;KACT,aAAa;KACb,WAAW,EACV,KAAK;MACJ,aAAa;MACb,SAAS,EACR,oBAAoB,EACnB,QAAQ;OACP,MAAM;OACN,YAAY,EACX,QAAQ,EACP,MAAM,WACN,EACD;OACD,EACD,EACD;MACD,EACD;KACD,EACD;IACD,EACD,OAAO,QAAQ;AACd,QAAI,SAAS,SAAS;AACrB,SAAI,QAAQ,OAAO,MAClB,qFACA;AACD,WAAM,SAAS,KAAK,eAAe;MAClC,SAAS;MACT,MAAM;MACN,CAAC;;IAEH,MAAM,EAAE,SAAS,OAAO,YAAY,MAAM,gBAAgB,IAAI;IAC9D,MAAM,OAAO,QAAQ;IACrB,MAAM,YAAY,MAAM,IAAI,QAAQ,QAAQ,QAAwB;KACnE,OAAO;KACP,OAAO,CACN;MACC,OAAO;MACP,OAAO,KAAK;MACZ,CACD;KACD,CAAC;AAEF,QAAI,CAAC,UACJ,OAAM,SAAS,KACd,eACA,uBAAuB,iBACvB;AAUF,QAAI,CAJW,MAAM,UAJH,MAAM,iBAAiB;KACxC,KAAK,IAAI,QAAQ;KACjB,MAAM,UAAU;KAChB,CAAC,EACwC;KACzC,QAAQ,KAAK;KACb,QAAQ,KAAK;KACb,CAAC,CAAC,OAAO,IAAI,KAAK,KAAK,CAEvB,QAAO,QAAQ,eAAe;AAG/B,QAAI,CAAC,KAAK,kBAAkB;AAC3B,SAAI,CAAC,QAAQ,QACZ,OAAM,SAAS,KACd,eACA,iBAAiB,yBACjB;KAEF,MAAM,cAAc,MAAM,IAAI,QAAQ,gBAAgB,WACrD,KAAK,IACL,EACC,kBAAkB,MAClB,CACD;KACD,MAAM,aAAa,MAAM,IAAI,QAAQ,gBACnC,cAAc,KAAK,IAAI,OAAO,QAAQ,QAAQ,CAC9C,OAAO,MAAM;AACb,YAAM;OACL;AAEH,WAAM,IAAI,QAAQ,gBAAgB,cAAc,QAAQ,QAAQ,MAAM;AACtE,WAAM,iBAAiB,KAAK;MAC3B,SAAS;MACT,MAAM;MACN,CAAC;;AAEH,WAAO,MAAM,IAAI;KAElB;GAkDC;EACD"}
@@ -0,0 +1,73 @@
1
+ import { User } from "../../types/models.mjs";
2
+ import { InferOptionSchema } from "../../types/plugins.mjs";
3
+ import "../../types/index.mjs";
4
+ import { BackupCodeOptions } from "./backup-codes/index.mjs";
5
+ import { OTPOptions } from "./otp/index.mjs";
6
+ import { schema } from "./schema.mjs";
7
+ import { TOTPOptions } from "./totp/index.mjs";
8
+ import { BetterAuthPlugin, LiteralString } from "@better-auth/core";
9
+
10
+ //#region src/plugins/two-factor/types.d.ts
11
+ interface TwoFactorOptions {
12
+ /**
13
+ * Application Name
14
+ */
15
+ issuer?: string | undefined;
16
+ /**
17
+ * TOTP OPtions
18
+ */
19
+ totpOptions?: Omit<TOTPOptions, "issuer"> | undefined;
20
+ /**
21
+ * OTP Options
22
+ */
23
+ otpOptions?: OTPOptions | undefined;
24
+ /**
25
+ * Backup code options
26
+ */
27
+ backupCodeOptions?: BackupCodeOptions | undefined;
28
+ /**
29
+ * Skip verification on enabling two factor authentication.
30
+ * @default false
31
+ */
32
+ skipVerificationOnEnable?: boolean | undefined;
33
+ /**
34
+ * Custom schema for the two factor plugin
35
+ */
36
+ schema?: InferOptionSchema<typeof schema> | undefined;
37
+ /**
38
+ * Maximum age (in seconds) for the two-factor verification cookie.
39
+ * This controls how long users have to complete the 2FA flow
40
+ * after signing in.
41
+ *
42
+ * @default 600 (10 minutes)
43
+ */
44
+ twoFactorCookieMaxAge?: number | undefined;
45
+ /**
46
+ * Maximum age (in seconds) for the trusted device cookie.
47
+ * When a user opts to trust a device, this controls how long
48
+ * the device stays trusted before requiring 2FA again.
49
+ *
50
+ * @default 2592000 (30 days)
51
+ */
52
+ trustDeviceMaxAge?: number | undefined;
53
+ }
54
+ interface UserWithTwoFactor extends User {
55
+ /**
56
+ * If the user has enabled two factor authentication.
57
+ */
58
+ twoFactorEnabled: boolean;
59
+ }
60
+ interface TwoFactorProvider {
61
+ id: LiteralString;
62
+ endpoints?: BetterAuthPlugin["endpoints"] | undefined;
63
+ }
64
+ interface TwoFactorTable {
65
+ id: string;
66
+ userId: string;
67
+ secret: string;
68
+ backupCodes: string;
69
+ enabled: boolean;
70
+ }
71
+ //#endregion
72
+ export { TwoFactorOptions, TwoFactorProvider, TwoFactorTable, UserWithTwoFactor };
73
+ //# sourceMappingURL=types.d.mts.map
@@ -0,0 +1,12 @@
1
+ import { base64Url } from "@better-auth/utils/base64";
2
+ import { createHash } from "@better-auth/utils/hash";
3
+
4
+ //#region src/plugins/two-factor/utils.ts
5
+ const defaultKeyHasher = async (token) => {
6
+ const hash = await createHash("SHA-256").digest(new TextEncoder().encode(token));
7
+ return base64Url.encode(new Uint8Array(hash), { padding: false });
8
+ };
9
+
10
+ //#endregion
11
+ export { defaultKeyHasher };
12
+ //# sourceMappingURL=utils.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.mjs","names":[],"sources":["../../../src/plugins/two-factor/utils.ts"],"sourcesContent":["import { base64Url } from \"@better-auth/utils/base64\";\nimport { createHash } from \"@better-auth/utils/hash\";\n\nexport const defaultKeyHasher = async (token: string) => {\n\tconst hash = await createHash(\"SHA-256\").digest(\n\t\tnew TextEncoder().encode(token),\n\t);\n\tconst hashed = base64Url.encode(new Uint8Array(hash), {\n\t\tpadding: false,\n\t});\n\treturn hashed;\n};\n"],"mappings":";;;;AAGA,MAAa,mBAAmB,OAAO,UAAkB;CACxD,MAAM,OAAO,MAAM,WAAW,UAAU,CAAC,OACxC,IAAI,aAAa,CAAC,OAAO,MAAM,CAC/B;AAID,QAHe,UAAU,OAAO,IAAI,WAAW,KAAK,EAAE,EACrD,SAAS,OACT,CAAC"}
@@ -0,0 +1,85 @@
1
+ import { parseUserOutput } from "../../db/schema.mjs";
2
+ import { generateRandomString } from "../../crypto/random.mjs";
3
+ import { expireCookie, setSessionCookie } from "../../cookies/index.mjs";
4
+ import { getSessionFromCtx } from "../../api/routes/session.mjs";
5
+ import "../../api/index.mjs";
6
+ import { TWO_FACTOR_ERROR_CODES } from "./error-code.mjs";
7
+ import { TRUST_DEVICE_COOKIE_MAX_AGE, TRUST_DEVICE_COOKIE_NAME, TWO_FACTOR_COOKIE_NAME } from "./constant.mjs";
8
+ import { APIError } from "@better-auth/core/error";
9
+ import { createHMAC } from "@better-auth/utils/hmac";
10
+
11
+ //#region src/plugins/two-factor/verify-two-factor.ts
12
+ async function verifyTwoFactor(ctx) {
13
+ const invalid = (errorKey) => {
14
+ throw APIError.from("UNAUTHORIZED", TWO_FACTOR_ERROR_CODES[errorKey]);
15
+ };
16
+ const session = await getSessionFromCtx(ctx);
17
+ if (!session) {
18
+ const twoFactorCookie = ctx.context.createAuthCookie(TWO_FACTOR_COOKIE_NAME);
19
+ const signedTwoFactorCookie = await ctx.getSignedCookie(twoFactorCookie.name, ctx.context.secret);
20
+ if (!signedTwoFactorCookie) throw APIError.from("UNAUTHORIZED", TWO_FACTOR_ERROR_CODES.INVALID_TWO_FACTOR_COOKIE);
21
+ const verificationToken = await ctx.context.internalAdapter.findVerificationValue(signedTwoFactorCookie);
22
+ if (!verificationToken) throw APIError.from("UNAUTHORIZED", TWO_FACTOR_ERROR_CODES.INVALID_TWO_FACTOR_COOKIE);
23
+ const user = await ctx.context.internalAdapter.findUserById(verificationToken.value);
24
+ if (!user) throw APIError.from("UNAUTHORIZED", TWO_FACTOR_ERROR_CODES.INVALID_TWO_FACTOR_COOKIE);
25
+ const dontRememberMe = await ctx.getSignedCookie(ctx.context.authCookies.dontRememberToken.name, ctx.context.secret);
26
+ return {
27
+ valid: async (ctx) => {
28
+ const session = await ctx.context.internalAdapter.createSession(verificationToken.value, !!dontRememberMe);
29
+ if (!session) throw APIError.from("INTERNAL_SERVER_ERROR", {
30
+ message: "failed to create session",
31
+ code: "FAILED_TO_CREATE_SESSION"
32
+ });
33
+ await ctx.context.internalAdapter.deleteVerificationValue(verificationToken.id);
34
+ await setSessionCookie(ctx, {
35
+ session,
36
+ user
37
+ });
38
+ expireCookie(ctx, twoFactorCookie);
39
+ if (ctx.body.trustDevice) {
40
+ const maxAge = ctx.context.getPlugin("two-factor").options.trustDeviceMaxAge ?? TRUST_DEVICE_COOKIE_MAX_AGE;
41
+ const trustDeviceCookie = ctx.context.createAuthCookie(TRUST_DEVICE_COOKIE_NAME, { maxAge });
42
+ /**
43
+ * Create a random identifier for the trust device record.
44
+ * Store it in the verification table with an expiration
45
+ * so the server can validate and revoke it.
46
+ */
47
+ const trustIdentifier = `trust-device-${generateRandomString(32)}`;
48
+ const token = await createHMAC("SHA-256", "base64urlnopad").sign(ctx.context.secret, `${user.id}!${trustIdentifier}`);
49
+ await ctx.context.internalAdapter.createVerificationValue({
50
+ value: user.id,
51
+ identifier: trustIdentifier,
52
+ expiresAt: new Date(Date.now() + maxAge * 1e3)
53
+ });
54
+ await ctx.setSignedCookie(trustDeviceCookie.name, `${token}!${trustIdentifier}`, ctx.context.secret, trustDeviceCookie.attributes);
55
+ expireCookie(ctx, ctx.context.authCookies.dontRememberToken);
56
+ }
57
+ return ctx.json({
58
+ token: session.token,
59
+ user: parseUserOutput(ctx.context.options, user)
60
+ });
61
+ },
62
+ invalid,
63
+ session: {
64
+ session: null,
65
+ user
66
+ },
67
+ key: signedTwoFactorCookie
68
+ };
69
+ }
70
+ return {
71
+ valid: async (ctx) => {
72
+ return ctx.json({
73
+ token: session.session.token,
74
+ user: parseUserOutput(ctx.context.options, session.user)
75
+ });
76
+ },
77
+ invalid,
78
+ session,
79
+ key: `${session.user.id}!${session.session.id}`
80
+ };
81
+ }
82
+
83
+ //#endregion
84
+ export { verifyTwoFactor };
85
+ //# sourceMappingURL=verify-two-factor.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"verify-two-factor.mjs","names":[],"sources":["../../../src/plugins/two-factor/verify-two-factor.ts"],"sourcesContent":["import type { GenericEndpointContext } from \"@better-auth/core\";\nimport { APIError } from \"@better-auth/core/error\";\nimport { createHMAC } from \"@better-auth/utils/hmac\";\nimport { getSessionFromCtx } from \"../../api\";\nimport { expireCookie, setSessionCookie } from \"../../cookies\";\nimport { generateRandomString } from \"../../crypto/random\";\nimport { parseUserOutput } from \"../../db/schema\";\nimport {\n\tTRUST_DEVICE_COOKIE_MAX_AGE,\n\tTRUST_DEVICE_COOKIE_NAME,\n\tTWO_FACTOR_COOKIE_NAME,\n} from \"./constant\";\nimport { TWO_FACTOR_ERROR_CODES } from \"./error-code\";\nimport type { UserWithTwoFactor } from \"./types\";\n\nexport async function verifyTwoFactor(ctx: GenericEndpointContext) {\n\tconst invalid = (errorKey: keyof typeof TWO_FACTOR_ERROR_CODES) => {\n\t\tthrow APIError.from(\"UNAUTHORIZED\", TWO_FACTOR_ERROR_CODES[errorKey]);\n\t};\n\n\tconst session = await getSessionFromCtx(ctx);\n\tif (!session) {\n\t\tconst twoFactorCookie = ctx.context.createAuthCookie(\n\t\t\tTWO_FACTOR_COOKIE_NAME,\n\t\t);\n\t\tconst signedTwoFactorCookie = await ctx.getSignedCookie(\n\t\t\ttwoFactorCookie.name,\n\t\t\tctx.context.secret,\n\t\t);\n\t\tif (!signedTwoFactorCookie) {\n\t\t\tthrow APIError.from(\n\t\t\t\t\"UNAUTHORIZED\",\n\t\t\t\tTWO_FACTOR_ERROR_CODES.INVALID_TWO_FACTOR_COOKIE,\n\t\t\t);\n\t\t}\n\t\tconst verificationToken =\n\t\t\tawait ctx.context.internalAdapter.findVerificationValue(\n\t\t\t\tsignedTwoFactorCookie,\n\t\t\t);\n\t\tif (!verificationToken) {\n\t\t\tthrow APIError.from(\n\t\t\t\t\"UNAUTHORIZED\",\n\t\t\t\tTWO_FACTOR_ERROR_CODES.INVALID_TWO_FACTOR_COOKIE,\n\t\t\t);\n\t\t}\n\t\tconst user = (await ctx.context.internalAdapter.findUserById(\n\t\t\tverificationToken.value,\n\t\t)) as UserWithTwoFactor;\n\t\tif (!user) {\n\t\t\tthrow APIError.from(\n\t\t\t\t\"UNAUTHORIZED\",\n\t\t\t\tTWO_FACTOR_ERROR_CODES.INVALID_TWO_FACTOR_COOKIE,\n\t\t\t);\n\t\t}\n\t\tconst dontRememberMe = await ctx.getSignedCookie(\n\t\t\tctx.context.authCookies.dontRememberToken.name,\n\t\t\tctx.context.secret,\n\t\t);\n\t\treturn {\n\t\t\tvalid: async (ctx: GenericEndpointContext) => {\n\t\t\t\tconst session = await ctx.context.internalAdapter.createSession(\n\t\t\t\t\tverificationToken.value,\n\t\t\t\t\t!!dontRememberMe,\n\t\t\t\t);\n\t\t\t\tif (!session) {\n\t\t\t\t\tthrow APIError.from(\"INTERNAL_SERVER_ERROR\", {\n\t\t\t\t\t\tmessage: \"failed to create session\",\n\t\t\t\t\t\tcode: \"FAILED_TO_CREATE_SESSION\",\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t\t// Delete the verification token from the database after successful verification\n\t\t\t\tawait ctx.context.internalAdapter.deleteVerificationValue(\n\t\t\t\t\tverificationToken.id,\n\t\t\t\t);\n\t\t\t\tawait setSessionCookie(ctx, {\n\t\t\t\t\tsession,\n\t\t\t\t\tuser,\n\t\t\t\t});\n\t\t\t\t// Always clear the two factor cookie after successful verification\n\t\t\t\texpireCookie(ctx, twoFactorCookie);\n\t\t\t\tif (ctx.body.trustDevice) {\n\t\t\t\t\tconst plugin = ctx.context.getPlugin(\"two-factor\");\n\t\t\t\t\tconst trustDeviceMaxAge = plugin!.options.trustDeviceMaxAge;\n\t\t\t\t\tconst maxAge = trustDeviceMaxAge ?? TRUST_DEVICE_COOKIE_MAX_AGE;\n\t\t\t\t\tconst trustDeviceCookie = ctx.context.createAuthCookie(\n\t\t\t\t\t\tTRUST_DEVICE_COOKIE_NAME,\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tmaxAge,\n\t\t\t\t\t\t},\n\t\t\t\t\t);\n\t\t\t\t\t/**\n\t\t\t\t\t * Create a random identifier for the trust device record.\n\t\t\t\t\t * Store it in the verification table with an expiration\n\t\t\t\t\t * so the server can validate and revoke it.\n\t\t\t\t\t */\n\t\t\t\t\tconst trustIdentifier = `trust-device-${generateRandomString(32)}`;\n\t\t\t\t\tconst token = await createHMAC(\"SHA-256\", \"base64urlnopad\").sign(\n\t\t\t\t\t\tctx.context.secret,\n\t\t\t\t\t\t`${user.id}!${trustIdentifier}`,\n\t\t\t\t\t);\n\t\t\t\t\tawait ctx.context.internalAdapter.createVerificationValue({\n\t\t\t\t\t\tvalue: user.id,\n\t\t\t\t\t\tidentifier: trustIdentifier,\n\t\t\t\t\t\texpiresAt: new Date(Date.now() + maxAge * 1000),\n\t\t\t\t\t});\n\t\t\t\t\tawait ctx.setSignedCookie(\n\t\t\t\t\t\ttrustDeviceCookie.name,\n\t\t\t\t\t\t`${token}!${trustIdentifier}`,\n\t\t\t\t\t\tctx.context.secret,\n\t\t\t\t\t\ttrustDeviceCookie.attributes,\n\t\t\t\t\t);\n\t\t\t\t\t// delete the dont remember me cookie\n\t\t\t\t\texpireCookie(ctx, ctx.context.authCookies.dontRememberToken);\n\t\t\t\t}\n\t\t\t\treturn ctx.json({\n\t\t\t\t\ttoken: session.token,\n\t\t\t\t\tuser: parseUserOutput(ctx.context.options, user),\n\t\t\t\t});\n\t\t\t},\n\t\t\tinvalid,\n\t\t\tsession: {\n\t\t\t\tsession: null,\n\t\t\t\tuser,\n\t\t\t},\n\t\t\tkey: signedTwoFactorCookie,\n\t\t};\n\t}\n\treturn {\n\t\tvalid: async (ctx: GenericEndpointContext) => {\n\t\t\treturn ctx.json({\n\t\t\t\ttoken: session.session.token,\n\t\t\t\tuser: parseUserOutput(ctx.context.options, session.user),\n\t\t\t});\n\t\t},\n\t\tinvalid,\n\t\tsession,\n\t\tkey: `${session.user.id}!${session.session.id}`,\n\t};\n}\n"],"mappings":";;;;;;;;;;;AAeA,eAAsB,gBAAgB,KAA6B;CAClE,MAAM,WAAW,aAAkD;AAClE,QAAM,SAAS,KAAK,gBAAgB,uBAAuB,UAAU;;CAGtE,MAAM,UAAU,MAAM,kBAAkB,IAAI;AAC5C,KAAI,CAAC,SAAS;EACb,MAAM,kBAAkB,IAAI,QAAQ,iBACnC,uBACA;EACD,MAAM,wBAAwB,MAAM,IAAI,gBACvC,gBAAgB,MAChB,IAAI,QAAQ,OACZ;AACD,MAAI,CAAC,sBACJ,OAAM,SAAS,KACd,gBACA,uBAAuB,0BACvB;EAEF,MAAM,oBACL,MAAM,IAAI,QAAQ,gBAAgB,sBACjC,sBACA;AACF,MAAI,CAAC,kBACJ,OAAM,SAAS,KACd,gBACA,uBAAuB,0BACvB;EAEF,MAAM,OAAQ,MAAM,IAAI,QAAQ,gBAAgB,aAC/C,kBAAkB,MAClB;AACD,MAAI,CAAC,KACJ,OAAM,SAAS,KACd,gBACA,uBAAuB,0BACvB;EAEF,MAAM,iBAAiB,MAAM,IAAI,gBAChC,IAAI,QAAQ,YAAY,kBAAkB,MAC1C,IAAI,QAAQ,OACZ;AACD,SAAO;GACN,OAAO,OAAO,QAAgC;IAC7C,MAAM,UAAU,MAAM,IAAI,QAAQ,gBAAgB,cACjD,kBAAkB,OAClB,CAAC,CAAC,eACF;AACD,QAAI,CAAC,QACJ,OAAM,SAAS,KAAK,yBAAyB;KAC5C,SAAS;KACT,MAAM;KACN,CAAC;AAGH,UAAM,IAAI,QAAQ,gBAAgB,wBACjC,kBAAkB,GAClB;AACD,UAAM,iBAAiB,KAAK;KAC3B;KACA;KACA,CAAC;AAEF,iBAAa,KAAK,gBAAgB;AAClC,QAAI,IAAI,KAAK,aAAa;KAGzB,MAAM,SAFS,IAAI,QAAQ,UAAU,aAAa,CAChB,QAAQ,qBACN;KACpC,MAAM,oBAAoB,IAAI,QAAQ,iBACrC,0BACA,EACC,QACA,CACD;;;;;;KAMD,MAAM,kBAAkB,gBAAgB,qBAAqB,GAAG;KAChE,MAAM,QAAQ,MAAM,WAAW,WAAW,iBAAiB,CAAC,KAC3D,IAAI,QAAQ,QACZ,GAAG,KAAK,GAAG,GAAG,kBACd;AACD,WAAM,IAAI,QAAQ,gBAAgB,wBAAwB;MACzD,OAAO,KAAK;MACZ,YAAY;MACZ,WAAW,IAAI,KAAK,KAAK,KAAK,GAAG,SAAS,IAAK;MAC/C,CAAC;AACF,WAAM,IAAI,gBACT,kBAAkB,MAClB,GAAG,MAAM,GAAG,mBACZ,IAAI,QAAQ,QACZ,kBAAkB,WAClB;AAED,kBAAa,KAAK,IAAI,QAAQ,YAAY,kBAAkB;;AAE7D,WAAO,IAAI,KAAK;KACf,OAAO,QAAQ;KACf,MAAM,gBAAgB,IAAI,QAAQ,SAAS,KAAK;KAChD,CAAC;;GAEH;GACA,SAAS;IACR,SAAS;IACT;IACA;GACD,KAAK;GACL;;AAEF,QAAO;EACN,OAAO,OAAO,QAAgC;AAC7C,UAAO,IAAI,KAAK;IACf,OAAO,QAAQ,QAAQ;IACvB,MAAM,gBAAgB,IAAI,QAAQ,SAAS,QAAQ,KAAK;IACxD,CAAC;;EAEH;EACA;EACA,KAAK,GAAG,QAAQ,KAAK,GAAG,GAAG,QAAQ,QAAQ;EAC3C"}
@@ -0,0 +1,26 @@
1
+ import { USERNAME_ERROR_CODES } from "./error-codes.mjs";
2
+ import { username } from "./index.mjs";
3
+ import * as _better_auth_core_utils_error_codes0 from "@better-auth/core/utils/error-codes";
4
+
5
+ //#region src/plugins/username/client.d.ts
6
+ declare const usernameClient: () => {
7
+ id: "username";
8
+ $InferServerPlugin: ReturnType<typeof username>;
9
+ atomListeners: {
10
+ matcher: (path: string) => path is "/sign-in/username";
11
+ signal: "$sessionSignal";
12
+ }[];
13
+ $ERROR_CODES: {
14
+ EMAIL_NOT_VERIFIED: _better_auth_core_utils_error_codes0.RawError<"EMAIL_NOT_VERIFIED">;
15
+ INVALID_USERNAME_OR_PASSWORD: _better_auth_core_utils_error_codes0.RawError<"INVALID_USERNAME_OR_PASSWORD">;
16
+ UNEXPECTED_ERROR: _better_auth_core_utils_error_codes0.RawError<"UNEXPECTED_ERROR">;
17
+ USERNAME_IS_ALREADY_TAKEN: _better_auth_core_utils_error_codes0.RawError<"USERNAME_IS_ALREADY_TAKEN">;
18
+ USERNAME_TOO_SHORT: _better_auth_core_utils_error_codes0.RawError<"USERNAME_TOO_SHORT">;
19
+ USERNAME_TOO_LONG: _better_auth_core_utils_error_codes0.RawError<"USERNAME_TOO_LONG">;
20
+ INVALID_USERNAME: _better_auth_core_utils_error_codes0.RawError<"INVALID_USERNAME">;
21
+ INVALID_DISPLAY_USERNAME: _better_auth_core_utils_error_codes0.RawError<"INVALID_DISPLAY_USERNAME">;
22
+ };
23
+ };
24
+ //#endregion
25
+ export { usernameClient };
26
+ //# sourceMappingURL=client.d.mts.map
@@ -0,0 +1,18 @@
1
+ import { USERNAME_ERROR_CODES } from "./error-codes.mjs";
2
+
3
+ //#region src/plugins/username/client.ts
4
+ const usernameClient = () => {
5
+ return {
6
+ id: "username",
7
+ $InferServerPlugin: {},
8
+ atomListeners: [{
9
+ matcher: (path) => path === "/sign-in/username",
10
+ signal: "$sessionSignal"
11
+ }],
12
+ $ERROR_CODES: USERNAME_ERROR_CODES
13
+ };
14
+ };
15
+
16
+ //#endregion
17
+ export { usernameClient };
18
+ //# sourceMappingURL=client.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.mjs","names":[],"sources":["../../../src/plugins/username/client.ts"],"sourcesContent":["import type { BetterAuthClientPlugin } from \"@better-auth/core\";\nimport type { username } from \".\";\n\nimport { USERNAME_ERROR_CODES } from \"./error-codes\";\n\nexport * from \"./error-codes\";\n\nexport const usernameClient = () => {\n\treturn {\n\t\tid: \"username\",\n\t\t$InferServerPlugin: {} as ReturnType<typeof username>,\n\t\tatomListeners: [\n\t\t\t{\n\t\t\t\tmatcher: (path) => path === \"/sign-in/username\",\n\t\t\t\tsignal: \"$sessionSignal\",\n\t\t\t},\n\t\t],\n\t\t$ERROR_CODES: USERNAME_ERROR_CODES,\n\t} satisfies BetterAuthClientPlugin;\n};\n"],"mappings":";;;AAOA,MAAa,uBAAuB;AACnC,QAAO;EACN,IAAI;EACJ,oBAAoB,EAAE;EACtB,eAAe,CACd;GACC,UAAU,SAAS,SAAS;GAC5B,QAAQ;GACR,CACD;EACD,cAAc;EACd"}
@@ -0,0 +1,16 @@
1
+ import * as _better_auth_core_utils_error_codes0 from "@better-auth/core/utils/error-codes";
2
+
3
+ //#region src/plugins/username/error-codes.d.ts
4
+ declare const USERNAME_ERROR_CODES: {
5
+ EMAIL_NOT_VERIFIED: _better_auth_core_utils_error_codes0.RawError<"EMAIL_NOT_VERIFIED">;
6
+ INVALID_USERNAME_OR_PASSWORD: _better_auth_core_utils_error_codes0.RawError<"INVALID_USERNAME_OR_PASSWORD">;
7
+ UNEXPECTED_ERROR: _better_auth_core_utils_error_codes0.RawError<"UNEXPECTED_ERROR">;
8
+ USERNAME_IS_ALREADY_TAKEN: _better_auth_core_utils_error_codes0.RawError<"USERNAME_IS_ALREADY_TAKEN">;
9
+ USERNAME_TOO_SHORT: _better_auth_core_utils_error_codes0.RawError<"USERNAME_TOO_SHORT">;
10
+ USERNAME_TOO_LONG: _better_auth_core_utils_error_codes0.RawError<"USERNAME_TOO_LONG">;
11
+ INVALID_USERNAME: _better_auth_core_utils_error_codes0.RawError<"INVALID_USERNAME">;
12
+ INVALID_DISPLAY_USERNAME: _better_auth_core_utils_error_codes0.RawError<"INVALID_DISPLAY_USERNAME">;
13
+ };
14
+ //#endregion
15
+ export { USERNAME_ERROR_CODES };
16
+ //# sourceMappingURL=error-codes.d.mts.map
@@ -0,0 +1,17 @@
1
+ import { defineErrorCodes } from "@better-auth/core/utils/error-codes";
2
+
3
+ //#region src/plugins/username/error-codes.ts
4
+ const USERNAME_ERROR_CODES = defineErrorCodes({
5
+ INVALID_USERNAME_OR_PASSWORD: "Invalid username or password",
6
+ EMAIL_NOT_VERIFIED: "Email not verified",
7
+ UNEXPECTED_ERROR: "Unexpected error",
8
+ USERNAME_IS_ALREADY_TAKEN: "Username is already taken. Please try another.",
9
+ USERNAME_TOO_SHORT: "Username is too short",
10
+ USERNAME_TOO_LONG: "Username is too long",
11
+ INVALID_USERNAME: "Username is invalid",
12
+ INVALID_DISPLAY_USERNAME: "Display username is invalid"
13
+ });
14
+
15
+ //#endregion
16
+ export { USERNAME_ERROR_CODES };
17
+ //# sourceMappingURL=error-codes.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error-codes.mjs","names":[],"sources":["../../../src/plugins/username/error-codes.ts"],"sourcesContent":["import { defineErrorCodes } from \"@better-auth/core/utils/error-codes\";\n\nexport const USERNAME_ERROR_CODES = defineErrorCodes({\n\tINVALID_USERNAME_OR_PASSWORD: \"Invalid username or password\",\n\tEMAIL_NOT_VERIFIED: \"Email not verified\",\n\tUNEXPECTED_ERROR: \"Unexpected error\",\n\tUSERNAME_IS_ALREADY_TAKEN: \"Username is already taken. Please try another.\",\n\tUSERNAME_TOO_SHORT: \"Username is too short\",\n\tUSERNAME_TOO_LONG: \"Username is too long\",\n\tINVALID_USERNAME: \"Username is invalid\",\n\tINVALID_DISPLAY_USERNAME: \"Display username is invalid\",\n});\n"],"mappings":";;;AAEA,MAAa,uBAAuB,iBAAiB;CACpD,8BAA8B;CAC9B,oBAAoB;CACpB,kBAAkB;CAClB,2BAA2B;CAC3B,oBAAoB;CACpB,mBAAmB;CACnB,kBAAkB;CAClB,0BAA0B;CAC1B,CAAC"}
@@ -0,0 +1,251 @@
1
+ import { InferOptionSchema } from "../../types/plugins.mjs";
2
+ import { UsernameSchema } from "./schema.mjs";
3
+ import { USERNAME_ERROR_CODES } from "./error-codes.mjs";
4
+ import * as _better_auth_core0 from "@better-auth/core";
5
+ import * as _better_auth_core_db0 from "@better-auth/core/db";
6
+ import * as _better_auth_core_utils_error_codes0 from "@better-auth/core/utils/error-codes";
7
+ import * as better_call0 from "better-call";
8
+ import * as z from "zod";
9
+
10
+ //#region src/plugins/username/index.d.ts
11
+ declare module "@better-auth/core" {
12
+ interface BetterAuthPluginRegistry<AuthOptions, Options> {
13
+ username: {
14
+ creator: typeof username;
15
+ };
16
+ }
17
+ }
18
+ type UsernameOptions = {
19
+ schema?: InferOptionSchema<UsernameSchema> | undefined;
20
+ /**
21
+ * The minimum length of the username
22
+ *
23
+ * @default 3
24
+ */
25
+ minUsernameLength?: number | undefined;
26
+ /**
27
+ * The maximum length of the username
28
+ *
29
+ * @default 30
30
+ */
31
+ maxUsernameLength?: number | undefined;
32
+ /**
33
+ * A function to validate the username
34
+ *
35
+ * By default, the username should only contain alphanumeric characters and underscores
36
+ */
37
+ usernameValidator?: ((username: string) => boolean | Promise<boolean>) | undefined;
38
+ /**
39
+ * A function to validate the display username
40
+ *
41
+ * By default, no validation is applied to display username
42
+ */
43
+ displayUsernameValidator?: ((displayUsername: string) => boolean | Promise<boolean>) | undefined;
44
+ /**
45
+ * A function to normalize the username
46
+ *
47
+ * @default (username) => username.toLowerCase()
48
+ */
49
+ usernameNormalization?: (((username: string) => string) | false) | undefined;
50
+ /**
51
+ * A function to normalize the display username
52
+ *
53
+ * @default false
54
+ */
55
+ displayUsernameNormalization?: (((displayUsername: string) => string) | false) | undefined;
56
+ /**
57
+ * The order of validation
58
+ *
59
+ * @default { username: "pre-normalization", displayUsername: "pre-normalization" }
60
+ */
61
+ validationOrder?: {
62
+ /**
63
+ * The order of username validation
64
+ *
65
+ * @default "pre-normalization"
66
+ */
67
+ username?: "pre-normalization" | "post-normalization";
68
+ /**
69
+ * The order of display username validation
70
+ *
71
+ * @default "pre-normalization"
72
+ */
73
+ displayUsername?: "pre-normalization" | "post-normalization";
74
+ } | undefined;
75
+ };
76
+ declare const username: (options?: UsernameOptions | undefined) => {
77
+ id: "username";
78
+ init(ctx: _better_auth_core0.AuthContext): {
79
+ options: {
80
+ databaseHooks: {
81
+ user: {
82
+ create: {
83
+ before(user: {
84
+ id: string;
85
+ createdAt: Date;
86
+ updatedAt: Date;
87
+ email: string;
88
+ emailVerified: boolean;
89
+ name: string;
90
+ image?: string | null | undefined;
91
+ } & Record<string, unknown>, context: _better_auth_core0.GenericEndpointContext | null): Promise<{
92
+ data: {
93
+ displayUsername?: string | undefined;
94
+ username?: string | undefined;
95
+ id: string;
96
+ createdAt: Date;
97
+ updatedAt: Date;
98
+ email: string;
99
+ emailVerified: boolean;
100
+ name: string;
101
+ image?: string | null | undefined;
102
+ };
103
+ }>;
104
+ };
105
+ update: {
106
+ before(user: Partial<{
107
+ id: string;
108
+ createdAt: Date;
109
+ updatedAt: Date;
110
+ email: string;
111
+ emailVerified: boolean;
112
+ name: string;
113
+ image?: string | null | undefined;
114
+ }> & Record<string, unknown>, context: _better_auth_core0.GenericEndpointContext | null): Promise<{
115
+ data: {
116
+ displayUsername?: string | undefined;
117
+ username?: string | undefined;
118
+ id?: string | undefined;
119
+ createdAt?: Date | undefined;
120
+ updatedAt?: Date | undefined;
121
+ email?: string | undefined;
122
+ emailVerified?: boolean | undefined;
123
+ name?: string | undefined;
124
+ image?: string | null | undefined;
125
+ };
126
+ }>;
127
+ };
128
+ };
129
+ };
130
+ };
131
+ };
132
+ endpoints: {
133
+ signInUsername: better_call0.StrictEndpoint<"/sign-in/username", {
134
+ method: "POST";
135
+ body: z.ZodObject<{
136
+ username: z.ZodString;
137
+ password: z.ZodString;
138
+ rememberMe: z.ZodOptional<z.ZodBoolean>;
139
+ callbackURL: z.ZodOptional<z.ZodString>;
140
+ }, z.core.$strip>;
141
+ metadata: {
142
+ openapi: {
143
+ summary: string;
144
+ description: string;
145
+ responses: {
146
+ 200: {
147
+ description: string;
148
+ content: {
149
+ "application/json": {
150
+ schema: {
151
+ type: "object";
152
+ properties: {
153
+ token: {
154
+ type: string;
155
+ description: string;
156
+ };
157
+ user: {
158
+ $ref: string;
159
+ };
160
+ };
161
+ required: string[];
162
+ };
163
+ };
164
+ };
165
+ };
166
+ 422: {
167
+ description: string;
168
+ content: {
169
+ "application/json": {
170
+ schema: {
171
+ type: "object";
172
+ properties: {
173
+ message: {
174
+ type: string;
175
+ };
176
+ };
177
+ };
178
+ };
179
+ };
180
+ };
181
+ };
182
+ };
183
+ };
184
+ }, {
185
+ token: string;
186
+ user: {
187
+ id: string;
188
+ createdAt: Date;
189
+ updatedAt: Date;
190
+ email: string;
191
+ emailVerified: boolean;
192
+ name: string;
193
+ image?: string | null | undefined;
194
+ } & {
195
+ username: string;
196
+ displayUsername: string;
197
+ };
198
+ }>;
199
+ isUsernameAvailable: better_call0.StrictEndpoint<"/is-username-available", {
200
+ method: "POST";
201
+ body: z.ZodObject<{
202
+ username: z.ZodString;
203
+ }, z.core.$strip>;
204
+ }, {
205
+ available: boolean;
206
+ }>;
207
+ };
208
+ schema: {
209
+ user: {
210
+ fields: {
211
+ username: {
212
+ type: "string";
213
+ required: false;
214
+ sortable: true;
215
+ unique: true;
216
+ returned: true;
217
+ transform: {
218
+ input(value: _better_auth_core_db0.DBPrimitive): string | number | boolean | unknown[] | Date | Record<string, unknown> | null | undefined;
219
+ };
220
+ };
221
+ displayUsername: {
222
+ type: "string";
223
+ required: false;
224
+ transform: {
225
+ input(value: _better_auth_core_db0.DBPrimitive): string | number | boolean | unknown[] | Date | Record<string, unknown> | null | undefined;
226
+ };
227
+ };
228
+ };
229
+ };
230
+ };
231
+ hooks: {
232
+ before: {
233
+ matcher(context: _better_auth_core0.HookEndpointContext): boolean;
234
+ handler: (inputContext: better_call0.MiddlewareInputContext<better_call0.MiddlewareOptions>) => Promise<void>;
235
+ }[];
236
+ };
237
+ options: UsernameOptions | undefined;
238
+ $ERROR_CODES: {
239
+ EMAIL_NOT_VERIFIED: _better_auth_core_utils_error_codes0.RawError<"EMAIL_NOT_VERIFIED">;
240
+ INVALID_USERNAME_OR_PASSWORD: _better_auth_core_utils_error_codes0.RawError<"INVALID_USERNAME_OR_PASSWORD">;
241
+ UNEXPECTED_ERROR: _better_auth_core_utils_error_codes0.RawError<"UNEXPECTED_ERROR">;
242
+ USERNAME_IS_ALREADY_TAKEN: _better_auth_core_utils_error_codes0.RawError<"USERNAME_IS_ALREADY_TAKEN">;
243
+ USERNAME_TOO_SHORT: _better_auth_core_utils_error_codes0.RawError<"USERNAME_TOO_SHORT">;
244
+ USERNAME_TOO_LONG: _better_auth_core_utils_error_codes0.RawError<"USERNAME_TOO_LONG">;
245
+ INVALID_USERNAME: _better_auth_core_utils_error_codes0.RawError<"INVALID_USERNAME">;
246
+ INVALID_DISPLAY_USERNAME: _better_auth_core_utils_error_codes0.RawError<"INVALID_DISPLAY_USERNAME">;
247
+ };
248
+ };
249
+ //#endregion
250
+ export { USERNAME_ERROR_CODES, UsernameOptions, username };
251
+ //# sourceMappingURL=index.d.mts.map