@hammadj/better-auth 1.5.0-beta.10

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 (687) hide show
  1. package/README.md +33 -0
  2. package/dist/_virtual/rolldown_runtime.mjs +36 -0
  3. package/dist/adapters/drizzle-adapter/index.d.mts +1 -0
  4. package/dist/adapters/drizzle-adapter/index.mjs +3 -0
  5. package/dist/adapters/index.d.mts +23 -0
  6. package/dist/adapters/index.mjs +13 -0
  7. package/dist/adapters/index.mjs.map +1 -0
  8. package/dist/adapters/kysely-adapter/index.d.mts +1 -0
  9. package/dist/adapters/kysely-adapter/index.mjs +3 -0
  10. package/dist/adapters/memory-adapter/index.d.mts +1 -0
  11. package/dist/adapters/memory-adapter/index.mjs +3 -0
  12. package/dist/adapters/mongodb-adapter/index.d.mts +1 -0
  13. package/dist/adapters/mongodb-adapter/index.mjs +3 -0
  14. package/dist/adapters/prisma-adapter/index.d.mts +1 -0
  15. package/dist/adapters/prisma-adapter/index.mjs +3 -0
  16. package/dist/api/index.d.mts +40 -0
  17. package/dist/api/index.mjs +205 -0
  18. package/dist/api/index.mjs.map +1 -0
  19. package/dist/api/middlewares/index.d.mts +1 -0
  20. package/dist/api/middlewares/index.mjs +3 -0
  21. package/dist/api/middlewares/origin-check.d.mts +17 -0
  22. package/dist/api/middlewares/origin-check.mjs +140 -0
  23. package/dist/api/middlewares/origin-check.mjs.map +1 -0
  24. package/dist/api/rate-limiter/index.mjs +177 -0
  25. package/dist/api/rate-limiter/index.mjs.map +1 -0
  26. package/dist/api/routes/account.d.mts +10 -0
  27. package/dist/api/routes/account.mjs +493 -0
  28. package/dist/api/routes/account.mjs.map +1 -0
  29. package/dist/api/routes/callback.d.mts +5 -0
  30. package/dist/api/routes/callback.mjs +178 -0
  31. package/dist/api/routes/callback.mjs.map +1 -0
  32. package/dist/api/routes/email-verification.d.mts +29 -0
  33. package/dist/api/routes/email-verification.mjs +301 -0
  34. package/dist/api/routes/email-verification.mjs.map +1 -0
  35. package/dist/api/routes/error.d.mts +5 -0
  36. package/dist/api/routes/error.mjs +386 -0
  37. package/dist/api/routes/error.mjs.map +1 -0
  38. package/dist/api/routes/index.d.mts +11 -0
  39. package/dist/api/routes/index.mjs +13 -0
  40. package/dist/api/routes/ok.d.mts +5 -0
  41. package/dist/api/routes/ok.mjs +30 -0
  42. package/dist/api/routes/ok.mjs.map +1 -0
  43. package/dist/api/routes/password.d.mts +8 -0
  44. package/dist/api/routes/password.mjs +198 -0
  45. package/dist/api/routes/password.mjs.map +1 -0
  46. package/dist/api/routes/session.d.mts +52 -0
  47. package/dist/api/routes/session.mjs +478 -0
  48. package/dist/api/routes/session.mjs.map +1 -0
  49. package/dist/api/routes/sign-in.d.mts +8 -0
  50. package/dist/api/routes/sign-in.mjs +262 -0
  51. package/dist/api/routes/sign-in.mjs.map +1 -0
  52. package/dist/api/routes/sign-out.d.mts +5 -0
  53. package/dist/api/routes/sign-out.mjs +33 -0
  54. package/dist/api/routes/sign-out.mjs.map +1 -0
  55. package/dist/api/routes/sign-up.d.mts +7 -0
  56. package/dist/api/routes/sign-up.mjs +227 -0
  57. package/dist/api/routes/sign-up.mjs.map +1 -0
  58. package/dist/api/routes/update-user.d.mts +12 -0
  59. package/dist/api/routes/update-user.mjs +493 -0
  60. package/dist/api/routes/update-user.mjs.map +1 -0
  61. package/dist/api/state/oauth.d.mts +5 -0
  62. package/dist/api/state/oauth.mjs +8 -0
  63. package/dist/api/state/oauth.mjs.map +1 -0
  64. package/dist/api/state/should-session-refresh.d.mts +13 -0
  65. package/dist/api/state/should-session-refresh.mjs +16 -0
  66. package/dist/api/state/should-session-refresh.mjs.map +1 -0
  67. package/dist/api/to-auth-endpoints.mjs +197 -0
  68. package/dist/api/to-auth-endpoints.mjs.map +1 -0
  69. package/dist/auth/base.mjs +44 -0
  70. package/dist/auth/base.mjs.map +1 -0
  71. package/dist/auth/full.d.mts +30 -0
  72. package/dist/auth/full.mjs +32 -0
  73. package/dist/auth/full.mjs.map +1 -0
  74. package/dist/auth/minimal.d.mts +12 -0
  75. package/dist/auth/minimal.mjs +14 -0
  76. package/dist/auth/minimal.mjs.map +1 -0
  77. package/dist/auth/trusted-origins.mjs +31 -0
  78. package/dist/auth/trusted-origins.mjs.map +1 -0
  79. package/dist/client/broadcast-channel.d.mts +20 -0
  80. package/dist/client/broadcast-channel.mjs +46 -0
  81. package/dist/client/broadcast-channel.mjs.map +1 -0
  82. package/dist/client/config.mjs +90 -0
  83. package/dist/client/config.mjs.map +1 -0
  84. package/dist/client/fetch-plugins.mjs +18 -0
  85. package/dist/client/fetch-plugins.mjs.map +1 -0
  86. package/dist/client/focus-manager.d.mts +11 -0
  87. package/dist/client/focus-manager.mjs +32 -0
  88. package/dist/client/focus-manager.mjs.map +1 -0
  89. package/dist/client/index.d.mts +30 -0
  90. package/dist/client/index.mjs +21 -0
  91. package/dist/client/index.mjs.map +1 -0
  92. package/dist/client/lynx/index.d.mts +62 -0
  93. package/dist/client/lynx/index.mjs +24 -0
  94. package/dist/client/lynx/index.mjs.map +1 -0
  95. package/dist/client/lynx/lynx-store.d.mts +47 -0
  96. package/dist/client/lynx/lynx-store.mjs +47 -0
  97. package/dist/client/lynx/lynx-store.mjs.map +1 -0
  98. package/dist/client/online-manager.d.mts +12 -0
  99. package/dist/client/online-manager.mjs +35 -0
  100. package/dist/client/online-manager.mjs.map +1 -0
  101. package/dist/client/parser.mjs +73 -0
  102. package/dist/client/parser.mjs.map +1 -0
  103. package/dist/client/path-to-object.d.mts +57 -0
  104. package/dist/client/plugins/index.d.mts +58 -0
  105. package/dist/client/plugins/index.mjs +33 -0
  106. package/dist/client/plugins/infer-plugin.d.mts +9 -0
  107. package/dist/client/plugins/infer-plugin.mjs +11 -0
  108. package/dist/client/plugins/infer-plugin.mjs.map +1 -0
  109. package/dist/client/proxy.mjs +79 -0
  110. package/dist/client/proxy.mjs.map +1 -0
  111. package/dist/client/query.d.mts +23 -0
  112. package/dist/client/query.mjs +98 -0
  113. package/dist/client/query.mjs.map +1 -0
  114. package/dist/client/react/index.d.mts +63 -0
  115. package/dist/client/react/index.mjs +24 -0
  116. package/dist/client/react/index.mjs.map +1 -0
  117. package/dist/client/react/react-store.d.mts +47 -0
  118. package/dist/client/react/react-store.mjs +47 -0
  119. package/dist/client/react/react-store.mjs.map +1 -0
  120. package/dist/client/session-atom.mjs +29 -0
  121. package/dist/client/session-atom.mjs.map +1 -0
  122. package/dist/client/session-refresh.d.mts +28 -0
  123. package/dist/client/session-refresh.mjs +140 -0
  124. package/dist/client/session-refresh.mjs.map +1 -0
  125. package/dist/client/solid/index.d.mts +57 -0
  126. package/dist/client/solid/index.mjs +22 -0
  127. package/dist/client/solid/index.mjs.map +1 -0
  128. package/dist/client/solid/solid-store.mjs +24 -0
  129. package/dist/client/solid/solid-store.mjs.map +1 -0
  130. package/dist/client/svelte/index.d.mts +63 -0
  131. package/dist/client/svelte/index.mjs +20 -0
  132. package/dist/client/svelte/index.mjs.map +1 -0
  133. package/dist/client/types.d.mts +58 -0
  134. package/dist/client/vanilla.d.mts +62 -0
  135. package/dist/client/vanilla.mjs +20 -0
  136. package/dist/client/vanilla.mjs.map +1 -0
  137. package/dist/client/vue/index.d.mts +86 -0
  138. package/dist/client/vue/index.mjs +38 -0
  139. package/dist/client/vue/index.mjs.map +1 -0
  140. package/dist/client/vue/vue-store.mjs +26 -0
  141. package/dist/client/vue/vue-store.mjs.map +1 -0
  142. package/dist/context/create-context.mjs +211 -0
  143. package/dist/context/create-context.mjs.map +1 -0
  144. package/dist/context/helpers.mjs +62 -0
  145. package/dist/context/helpers.mjs.map +1 -0
  146. package/dist/context/init-minimal.mjs +20 -0
  147. package/dist/context/init-minimal.mjs.map +1 -0
  148. package/dist/context/init.mjs +22 -0
  149. package/dist/context/init.mjs.map +1 -0
  150. package/dist/cookies/cookie-utils.d.mts +29 -0
  151. package/dist/cookies/cookie-utils.mjs +105 -0
  152. package/dist/cookies/cookie-utils.mjs.map +1 -0
  153. package/dist/cookies/index.d.mts +67 -0
  154. package/dist/cookies/index.mjs +264 -0
  155. package/dist/cookies/index.mjs.map +1 -0
  156. package/dist/cookies/session-store.d.mts +36 -0
  157. package/dist/cookies/session-store.mjs +200 -0
  158. package/dist/cookies/session-store.mjs.map +1 -0
  159. package/dist/crypto/buffer.d.mts +8 -0
  160. package/dist/crypto/buffer.mjs +18 -0
  161. package/dist/crypto/buffer.mjs.map +1 -0
  162. package/dist/crypto/index.d.mts +27 -0
  163. package/dist/crypto/index.mjs +38 -0
  164. package/dist/crypto/index.mjs.map +1 -0
  165. package/dist/crypto/jwt.d.mts +8 -0
  166. package/dist/crypto/jwt.mjs +95 -0
  167. package/dist/crypto/jwt.mjs.map +1 -0
  168. package/dist/crypto/password.d.mts +12 -0
  169. package/dist/crypto/password.mjs +36 -0
  170. package/dist/crypto/password.mjs.map +1 -0
  171. package/dist/crypto/random.d.mts +5 -0
  172. package/dist/crypto/random.mjs +8 -0
  173. package/dist/crypto/random.mjs.map +1 -0
  174. package/dist/db/adapter-base.d.mts +8 -0
  175. package/dist/db/adapter-base.mjs +28 -0
  176. package/dist/db/adapter-base.mjs.map +1 -0
  177. package/dist/db/adapter-kysely.d.mts +8 -0
  178. package/dist/db/adapter-kysely.mjs +21 -0
  179. package/dist/db/adapter-kysely.mjs.map +1 -0
  180. package/dist/db/field-converter.d.mts +8 -0
  181. package/dist/db/field-converter.mjs +21 -0
  182. package/dist/db/field-converter.mjs.map +1 -0
  183. package/dist/db/field.d.mts +55 -0
  184. package/dist/db/field.mjs +11 -0
  185. package/dist/db/field.mjs.map +1 -0
  186. package/dist/db/get-migration.d.mts +23 -0
  187. package/dist/db/get-migration.mjs +339 -0
  188. package/dist/db/get-migration.mjs.map +1 -0
  189. package/dist/db/get-schema.d.mts +11 -0
  190. package/dist/db/get-schema.mjs +39 -0
  191. package/dist/db/get-schema.mjs.map +1 -0
  192. package/dist/db/index.d.mts +9 -0
  193. package/dist/db/index.mjs +36 -0
  194. package/dist/db/index.mjs.map +1 -0
  195. package/dist/db/internal-adapter.d.mts +14 -0
  196. package/dist/db/internal-adapter.mjs +616 -0
  197. package/dist/db/internal-adapter.mjs.map +1 -0
  198. package/dist/db/schema.d.mts +26 -0
  199. package/dist/db/schema.mjs +118 -0
  200. package/dist/db/schema.mjs.map +1 -0
  201. package/dist/db/to-zod.d.mts +36 -0
  202. package/dist/db/to-zod.mjs +26 -0
  203. package/dist/db/to-zod.mjs.map +1 -0
  204. package/dist/db/verification-token-storage.mjs +28 -0
  205. package/dist/db/verification-token-storage.mjs.map +1 -0
  206. package/dist/db/with-hooks.d.mts +33 -0
  207. package/dist/db/with-hooks.mjs +159 -0
  208. package/dist/db/with-hooks.mjs.map +1 -0
  209. package/dist/index.d.mts +52 -0
  210. package/dist/index.mjs +26 -0
  211. package/dist/integrations/next-js.d.mts +14 -0
  212. package/dist/integrations/next-js.mjs +78 -0
  213. package/dist/integrations/next-js.mjs.map +1 -0
  214. package/dist/integrations/node.d.mts +13 -0
  215. package/dist/integrations/node.mjs +16 -0
  216. package/dist/integrations/node.mjs.map +1 -0
  217. package/dist/integrations/solid-start.d.mts +23 -0
  218. package/dist/integrations/solid-start.mjs +17 -0
  219. package/dist/integrations/solid-start.mjs.map +1 -0
  220. package/dist/integrations/svelte-kit.d.mts +29 -0
  221. package/dist/integrations/svelte-kit.mjs +57 -0
  222. package/dist/integrations/svelte-kit.mjs.map +1 -0
  223. package/dist/integrations/tanstack-start-solid.d.mts +22 -0
  224. package/dist/integrations/tanstack-start-solid.mjs +61 -0
  225. package/dist/integrations/tanstack-start-solid.mjs.map +1 -0
  226. package/dist/integrations/tanstack-start.d.mts +22 -0
  227. package/dist/integrations/tanstack-start.mjs +61 -0
  228. package/dist/integrations/tanstack-start.mjs.map +1 -0
  229. package/dist/oauth2/index.d.mts +5 -0
  230. package/dist/oauth2/index.mjs +7 -0
  231. package/dist/oauth2/link-account.d.mts +31 -0
  232. package/dist/oauth2/link-account.mjs +144 -0
  233. package/dist/oauth2/link-account.mjs.map +1 -0
  234. package/dist/oauth2/state.d.mts +26 -0
  235. package/dist/oauth2/state.mjs +51 -0
  236. package/dist/oauth2/state.mjs.map +1 -0
  237. package/dist/oauth2/utils.d.mts +8 -0
  238. package/dist/oauth2/utils.mjs +31 -0
  239. package/dist/oauth2/utils.mjs.map +1 -0
  240. package/dist/plugins/access/access.d.mts +30 -0
  241. package/dist/plugins/access/access.mjs +46 -0
  242. package/dist/plugins/access/access.mjs.map +1 -0
  243. package/dist/plugins/access/index.d.mts +3 -0
  244. package/dist/plugins/access/index.mjs +3 -0
  245. package/dist/plugins/access/types.d.mts +17 -0
  246. package/dist/plugins/additional-fields/client.d.mts +14 -0
  247. package/dist/plugins/additional-fields/client.mjs +11 -0
  248. package/dist/plugins/additional-fields/client.mjs.map +1 -0
  249. package/dist/plugins/admin/access/index.d.mts +2 -0
  250. package/dist/plugins/admin/access/index.mjs +3 -0
  251. package/dist/plugins/admin/access/statement.d.mts +118 -0
  252. package/dist/plugins/admin/access/statement.mjs +53 -0
  253. package/dist/plugins/admin/access/statement.mjs.map +1 -0
  254. package/dist/plugins/admin/admin.d.mts +14 -0
  255. package/dist/plugins/admin/admin.mjs +95 -0
  256. package/dist/plugins/admin/admin.mjs.map +1 -0
  257. package/dist/plugins/admin/client.d.mts +14 -0
  258. package/dist/plugins/admin/client.mjs +36 -0
  259. package/dist/plugins/admin/client.mjs.map +1 -0
  260. package/dist/plugins/admin/error-codes.d.mts +5 -0
  261. package/dist/plugins/admin/error-codes.mjs +30 -0
  262. package/dist/plugins/admin/error-codes.mjs.map +1 -0
  263. package/dist/plugins/admin/has-permission.mjs +16 -0
  264. package/dist/plugins/admin/has-permission.mjs.map +1 -0
  265. package/dist/plugins/admin/index.d.mts +3 -0
  266. package/dist/plugins/admin/index.mjs +3 -0
  267. package/dist/plugins/admin/routes.mjs +855 -0
  268. package/dist/plugins/admin/routes.mjs.map +1 -0
  269. package/dist/plugins/admin/schema.d.mts +6 -0
  270. package/dist/plugins/admin/schema.mjs +34 -0
  271. package/dist/plugins/admin/schema.mjs.map +1 -0
  272. package/dist/plugins/admin/types.d.mts +89 -0
  273. package/dist/plugins/anonymous/client.d.mts +9 -0
  274. package/dist/plugins/anonymous/client.mjs +22 -0
  275. package/dist/plugins/anonymous/client.mjs.map +1 -0
  276. package/dist/plugins/anonymous/error-codes.d.mts +5 -0
  277. package/dist/plugins/anonymous/error-codes.mjs +16 -0
  278. package/dist/plugins/anonymous/error-codes.mjs.map +1 -0
  279. package/dist/plugins/anonymous/index.d.mts +14 -0
  280. package/dist/plugins/anonymous/index.mjs +163 -0
  281. package/dist/plugins/anonymous/index.mjs.map +1 -0
  282. package/dist/plugins/anonymous/schema.d.mts +5 -0
  283. package/dist/plugins/anonymous/schema.mjs +11 -0
  284. package/dist/plugins/anonymous/schema.mjs.map +1 -0
  285. package/dist/plugins/anonymous/types.d.mts +68 -0
  286. package/dist/plugins/api-key/adapter.mjs +468 -0
  287. package/dist/plugins/api-key/adapter.mjs.map +1 -0
  288. package/dist/plugins/api-key/client.d.mts +9 -0
  289. package/dist/plugins/api-key/client.mjs +19 -0
  290. package/dist/plugins/api-key/client.mjs.map +1 -0
  291. package/dist/plugins/api-key/error-codes.d.mts +5 -0
  292. package/dist/plugins/api-key/error-codes.mjs +34 -0
  293. package/dist/plugins/api-key/error-codes.mjs.map +1 -0
  294. package/dist/plugins/api-key/index.d.mts +17 -0
  295. package/dist/plugins/api-key/index.mjs +134 -0
  296. package/dist/plugins/api-key/index.mjs.map +1 -0
  297. package/dist/plugins/api-key/rate-limit.mjs +74 -0
  298. package/dist/plugins/api-key/rate-limit.mjs.map +1 -0
  299. package/dist/plugins/api-key/routes/create-api-key.mjs +252 -0
  300. package/dist/plugins/api-key/routes/create-api-key.mjs.map +1 -0
  301. package/dist/plugins/api-key/routes/delete-all-expired-api-keys.mjs +24 -0
  302. package/dist/plugins/api-key/routes/delete-all-expired-api-keys.mjs.map +1 -0
  303. package/dist/plugins/api-key/routes/delete-api-key.mjs +74 -0
  304. package/dist/plugins/api-key/routes/delete-api-key.mjs.map +1 -0
  305. package/dist/plugins/api-key/routes/get-api-key.mjs +158 -0
  306. package/dist/plugins/api-key/routes/get-api-key.mjs.map +1 -0
  307. package/dist/plugins/api-key/routes/index.mjs +71 -0
  308. package/dist/plugins/api-key/routes/index.mjs.map +1 -0
  309. package/dist/plugins/api-key/routes/list-api-keys.mjs +194 -0
  310. package/dist/plugins/api-key/routes/list-api-keys.mjs.map +1 -0
  311. package/dist/plugins/api-key/routes/update-api-key.mjs +248 -0
  312. package/dist/plugins/api-key/routes/update-api-key.mjs.map +1 -0
  313. package/dist/plugins/api-key/routes/verify-api-key.mjs +223 -0
  314. package/dist/plugins/api-key/routes/verify-api-key.mjs.map +1 -0
  315. package/dist/plugins/api-key/schema.d.mts +11 -0
  316. package/dist/plugins/api-key/schema.mjs +130 -0
  317. package/dist/plugins/api-key/schema.mjs.map +1 -0
  318. package/dist/plugins/api-key/types.d.mts +346 -0
  319. package/dist/plugins/bearer/index.d.mts +25 -0
  320. package/dist/plugins/bearer/index.mjs +66 -0
  321. package/dist/plugins/bearer/index.mjs.map +1 -0
  322. package/dist/plugins/captcha/constants.d.mts +10 -0
  323. package/dist/plugins/captcha/constants.mjs +22 -0
  324. package/dist/plugins/captcha/constants.mjs.map +1 -0
  325. package/dist/plugins/captcha/error-codes.mjs +16 -0
  326. package/dist/plugins/captcha/error-codes.mjs.map +1 -0
  327. package/dist/plugins/captcha/index.d.mts +14 -0
  328. package/dist/plugins/captcha/index.mjs +60 -0
  329. package/dist/plugins/captcha/index.mjs.map +1 -0
  330. package/dist/plugins/captcha/types.d.mts +28 -0
  331. package/dist/plugins/captcha/utils.mjs +11 -0
  332. package/dist/plugins/captcha/utils.mjs.map +1 -0
  333. package/dist/plugins/captcha/verify-handlers/captchafox.mjs +27 -0
  334. package/dist/plugins/captcha/verify-handlers/captchafox.mjs.map +1 -0
  335. package/dist/plugins/captcha/verify-handlers/cloudflare-turnstile.mjs +25 -0
  336. package/dist/plugins/captcha/verify-handlers/cloudflare-turnstile.mjs.map +1 -0
  337. package/dist/plugins/captcha/verify-handlers/google-recaptcha.mjs +29 -0
  338. package/dist/plugins/captcha/verify-handlers/google-recaptcha.mjs.map +1 -0
  339. package/dist/plugins/captcha/verify-handlers/h-captcha.mjs +27 -0
  340. package/dist/plugins/captcha/verify-handlers/h-captcha.mjs.map +1 -0
  341. package/dist/plugins/captcha/verify-handlers/index.mjs +6 -0
  342. package/dist/plugins/custom-session/client.d.mts +10 -0
  343. package/dist/plugins/custom-session/client.mjs +11 -0
  344. package/dist/plugins/custom-session/client.mjs.map +1 -0
  345. package/dist/plugins/custom-session/index.d.mts +26 -0
  346. package/dist/plugins/custom-session/index.mjs +70 -0
  347. package/dist/plugins/custom-session/index.mjs.map +1 -0
  348. package/dist/plugins/device-authorization/client.d.mts +5 -0
  349. package/dist/plugins/device-authorization/client.mjs +18 -0
  350. package/dist/plugins/device-authorization/client.mjs.map +1 -0
  351. package/dist/plugins/device-authorization/error-codes.mjs +21 -0
  352. package/dist/plugins/device-authorization/error-codes.mjs.map +1 -0
  353. package/dist/plugins/device-authorization/index.d.mts +28 -0
  354. package/dist/plugins/device-authorization/index.mjs +50 -0
  355. package/dist/plugins/device-authorization/index.mjs.map +1 -0
  356. package/dist/plugins/device-authorization/routes.mjs +510 -0
  357. package/dist/plugins/device-authorization/routes.mjs.map +1 -0
  358. package/dist/plugins/device-authorization/schema.mjs +57 -0
  359. package/dist/plugins/device-authorization/schema.mjs.map +1 -0
  360. package/dist/plugins/email-otp/client.d.mts +7 -0
  361. package/dist/plugins/email-otp/client.mjs +18 -0
  362. package/dist/plugins/email-otp/client.mjs.map +1 -0
  363. package/dist/plugins/email-otp/error-codes.d.mts +5 -0
  364. package/dist/plugins/email-otp/error-codes.mjs +12 -0
  365. package/dist/plugins/email-otp/error-codes.mjs.map +1 -0
  366. package/dist/plugins/email-otp/index.d.mts +14 -0
  367. package/dist/plugins/email-otp/index.mjs +108 -0
  368. package/dist/plugins/email-otp/index.mjs.map +1 -0
  369. package/dist/plugins/email-otp/otp-token.mjs +29 -0
  370. package/dist/plugins/email-otp/otp-token.mjs.map +1 -0
  371. package/dist/plugins/email-otp/routes.mjs +564 -0
  372. package/dist/plugins/email-otp/routes.mjs.map +1 -0
  373. package/dist/plugins/email-otp/types.d.mts +74 -0
  374. package/dist/plugins/email-otp/utils.mjs +17 -0
  375. package/dist/plugins/email-otp/utils.mjs.map +1 -0
  376. package/dist/plugins/generic-oauth/client.d.mts +19 -0
  377. package/dist/plugins/generic-oauth/client.mjs +14 -0
  378. package/dist/plugins/generic-oauth/client.mjs.map +1 -0
  379. package/dist/plugins/generic-oauth/error-codes.d.mts +5 -0
  380. package/dist/plugins/generic-oauth/error-codes.mjs +15 -0
  381. package/dist/plugins/generic-oauth/error-codes.mjs.map +1 -0
  382. package/dist/plugins/generic-oauth/index.d.mts +34 -0
  383. package/dist/plugins/generic-oauth/index.mjs +137 -0
  384. package/dist/plugins/generic-oauth/index.mjs.map +1 -0
  385. package/dist/plugins/generic-oauth/providers/auth0.d.mts +37 -0
  386. package/dist/plugins/generic-oauth/providers/auth0.mjs +62 -0
  387. package/dist/plugins/generic-oauth/providers/auth0.mjs.map +1 -0
  388. package/dist/plugins/generic-oauth/providers/gumroad.d.mts +32 -0
  389. package/dist/plugins/generic-oauth/providers/gumroad.mjs +60 -0
  390. package/dist/plugins/generic-oauth/providers/gumroad.mjs.map +1 -0
  391. package/dist/plugins/generic-oauth/providers/hubspot.d.mts +37 -0
  392. package/dist/plugins/generic-oauth/providers/hubspot.mjs +60 -0
  393. package/dist/plugins/generic-oauth/providers/hubspot.mjs.map +1 -0
  394. package/dist/plugins/generic-oauth/providers/index.d.mts +9 -0
  395. package/dist/plugins/generic-oauth/providers/index.mjs +11 -0
  396. package/dist/plugins/generic-oauth/providers/keycloak.d.mts +37 -0
  397. package/dist/plugins/generic-oauth/providers/keycloak.mjs +62 -0
  398. package/dist/plugins/generic-oauth/providers/keycloak.mjs.map +1 -0
  399. package/dist/plugins/generic-oauth/providers/line.d.mts +55 -0
  400. package/dist/plugins/generic-oauth/providers/line.mjs +91 -0
  401. package/dist/plugins/generic-oauth/providers/line.mjs.map +1 -0
  402. package/dist/plugins/generic-oauth/providers/microsoft-entra-id.d.mts +37 -0
  403. package/dist/plugins/generic-oauth/providers/microsoft-entra-id.mjs +66 -0
  404. package/dist/plugins/generic-oauth/providers/microsoft-entra-id.mjs.map +1 -0
  405. package/dist/plugins/generic-oauth/providers/okta.d.mts +37 -0
  406. package/dist/plugins/generic-oauth/providers/okta.mjs +62 -0
  407. package/dist/plugins/generic-oauth/providers/okta.mjs.map +1 -0
  408. package/dist/plugins/generic-oauth/providers/patreon.d.mts +30 -0
  409. package/dist/plugins/generic-oauth/providers/patreon.mjs +59 -0
  410. package/dist/plugins/generic-oauth/providers/patreon.mjs.map +1 -0
  411. package/dist/plugins/generic-oauth/providers/slack.d.mts +30 -0
  412. package/dist/plugins/generic-oauth/providers/slack.mjs +61 -0
  413. package/dist/plugins/generic-oauth/providers/slack.mjs.map +1 -0
  414. package/dist/plugins/generic-oauth/routes.mjs +394 -0
  415. package/dist/plugins/generic-oauth/routes.mjs.map +1 -0
  416. package/dist/plugins/generic-oauth/types.d.mts +145 -0
  417. package/dist/plugins/haveibeenpwned/index.d.mts +21 -0
  418. package/dist/plugins/haveibeenpwned/index.mjs +56 -0
  419. package/dist/plugins/haveibeenpwned/index.mjs.map +1 -0
  420. package/dist/plugins/index.d.mts +68 -0
  421. package/dist/plugins/index.mjs +51 -0
  422. package/dist/plugins/jwt/adapter.mjs +27 -0
  423. package/dist/plugins/jwt/adapter.mjs.map +1 -0
  424. package/dist/plugins/jwt/client.d.mts +18 -0
  425. package/dist/plugins/jwt/client.mjs +19 -0
  426. package/dist/plugins/jwt/client.mjs.map +1 -0
  427. package/dist/plugins/jwt/index.d.mts +17 -0
  428. package/dist/plugins/jwt/index.mjs +202 -0
  429. package/dist/plugins/jwt/index.mjs.map +1 -0
  430. package/dist/plugins/jwt/schema.d.mts +5 -0
  431. package/dist/plugins/jwt/schema.mjs +23 -0
  432. package/dist/plugins/jwt/schema.mjs.map +1 -0
  433. package/dist/plugins/jwt/sign.d.mts +57 -0
  434. package/dist/plugins/jwt/sign.mjs +66 -0
  435. package/dist/plugins/jwt/sign.mjs.map +1 -0
  436. package/dist/plugins/jwt/types.d.mts +194 -0
  437. package/dist/plugins/jwt/utils.d.mts +42 -0
  438. package/dist/plugins/jwt/utils.mjs +64 -0
  439. package/dist/plugins/jwt/utils.mjs.map +1 -0
  440. package/dist/plugins/jwt/verify.d.mts +12 -0
  441. package/dist/plugins/jwt/verify.mjs +46 -0
  442. package/dist/plugins/jwt/verify.mjs.map +1 -0
  443. package/dist/plugins/last-login-method/client.d.mts +18 -0
  444. package/dist/plugins/last-login-method/client.mjs +32 -0
  445. package/dist/plugins/last-login-method/client.mjs.map +1 -0
  446. package/dist/plugins/last-login-method/index.d.mts +52 -0
  447. package/dist/plugins/last-login-method/index.mjs +77 -0
  448. package/dist/plugins/last-login-method/index.mjs.map +1 -0
  449. package/dist/plugins/magic-link/client.d.mts +5 -0
  450. package/dist/plugins/magic-link/client.mjs +11 -0
  451. package/dist/plugins/magic-link/client.mjs.map +1 -0
  452. package/dist/plugins/magic-link/index.d.mts +61 -0
  453. package/dist/plugins/magic-link/index.mjs +167 -0
  454. package/dist/plugins/magic-link/index.mjs.map +1 -0
  455. package/dist/plugins/magic-link/utils.mjs +12 -0
  456. package/dist/plugins/magic-link/utils.mjs.map +1 -0
  457. package/dist/plugins/mcp/authorize.mjs +133 -0
  458. package/dist/plugins/mcp/authorize.mjs.map +1 -0
  459. package/dist/plugins/mcp/index.d.mts +46 -0
  460. package/dist/plugins/mcp/index.mjs +717 -0
  461. package/dist/plugins/mcp/index.mjs.map +1 -0
  462. package/dist/plugins/multi-session/client.d.mts +8 -0
  463. package/dist/plugins/multi-session/client.mjs +20 -0
  464. package/dist/plugins/multi-session/client.mjs.map +1 -0
  465. package/dist/plugins/multi-session/error-codes.d.mts +5 -0
  466. package/dist/plugins/multi-session/error-codes.mjs +8 -0
  467. package/dist/plugins/multi-session/error-codes.mjs.map +1 -0
  468. package/dist/plugins/multi-session/index.d.mts +22 -0
  469. package/dist/plugins/multi-session/index.mjs +172 -0
  470. package/dist/plugins/multi-session/index.mjs.map +1 -0
  471. package/dist/plugins/oauth-proxy/index.d.mts +39 -0
  472. package/dist/plugins/oauth-proxy/index.mjs +305 -0
  473. package/dist/plugins/oauth-proxy/index.mjs.map +1 -0
  474. package/dist/plugins/oauth-proxy/utils.mjs +44 -0
  475. package/dist/plugins/oauth-proxy/utils.mjs.map +1 -0
  476. package/dist/plugins/oidc-provider/authorize.mjs +194 -0
  477. package/dist/plugins/oidc-provider/authorize.mjs.map +1 -0
  478. package/dist/plugins/oidc-provider/client.d.mts +8 -0
  479. package/dist/plugins/oidc-provider/client.mjs +11 -0
  480. package/dist/plugins/oidc-provider/client.mjs.map +1 -0
  481. package/dist/plugins/oidc-provider/error.mjs +17 -0
  482. package/dist/plugins/oidc-provider/error.mjs.map +1 -0
  483. package/dist/plugins/oidc-provider/index.d.mts +32 -0
  484. package/dist/plugins/oidc-provider/index.mjs +1093 -0
  485. package/dist/plugins/oidc-provider/index.mjs.map +1 -0
  486. package/dist/plugins/oidc-provider/schema.d.mts +26 -0
  487. package/dist/plugins/oidc-provider/schema.mjs +132 -0
  488. package/dist/plugins/oidc-provider/schema.mjs.map +1 -0
  489. package/dist/plugins/oidc-provider/types.d.mts +517 -0
  490. package/dist/plugins/oidc-provider/utils/prompt.mjs +19 -0
  491. package/dist/plugins/oidc-provider/utils/prompt.mjs.map +1 -0
  492. package/dist/plugins/oidc-provider/utils.mjs +15 -0
  493. package/dist/plugins/oidc-provider/utils.mjs.map +1 -0
  494. package/dist/plugins/one-tap/client.d.mts +159 -0
  495. package/dist/plugins/one-tap/client.mjs +214 -0
  496. package/dist/plugins/one-tap/client.mjs.map +1 -0
  497. package/dist/plugins/one-tap/index.d.mts +27 -0
  498. package/dist/plugins/one-tap/index.mjs +96 -0
  499. package/dist/plugins/one-tap/index.mjs.map +1 -0
  500. package/dist/plugins/one-time-token/client.d.mts +7 -0
  501. package/dist/plugins/one-time-token/client.mjs +11 -0
  502. package/dist/plugins/one-time-token/client.mjs.map +1 -0
  503. package/dist/plugins/one-time-token/index.d.mts +53 -0
  504. package/dist/plugins/one-time-token/index.mjs +82 -0
  505. package/dist/plugins/one-time-token/index.mjs.map +1 -0
  506. package/dist/plugins/one-time-token/utils.mjs +12 -0
  507. package/dist/plugins/one-time-token/utils.mjs.map +1 -0
  508. package/dist/plugins/open-api/generator.d.mts +115 -0
  509. package/dist/plugins/open-api/generator.mjs +315 -0
  510. package/dist/plugins/open-api/generator.mjs.map +1 -0
  511. package/dist/plugins/open-api/index.d.mts +45 -0
  512. package/dist/plugins/open-api/index.mjs +67 -0
  513. package/dist/plugins/open-api/index.mjs.map +1 -0
  514. package/dist/plugins/open-api/logo.mjs +15 -0
  515. package/dist/plugins/open-api/logo.mjs.map +1 -0
  516. package/dist/plugins/organization/access/index.d.mts +2 -0
  517. package/dist/plugins/organization/access/index.mjs +3 -0
  518. package/dist/plugins/organization/access/statement.d.mts +249 -0
  519. package/dist/plugins/organization/access/statement.mjs +81 -0
  520. package/dist/plugins/organization/access/statement.mjs.map +1 -0
  521. package/dist/plugins/organization/adapter.d.mts +205 -0
  522. package/dist/plugins/organization/adapter.mjs +624 -0
  523. package/dist/plugins/organization/adapter.mjs.map +1 -0
  524. package/dist/plugins/organization/call.mjs +19 -0
  525. package/dist/plugins/organization/call.mjs.map +1 -0
  526. package/dist/plugins/organization/client.d.mts +151 -0
  527. package/dist/plugins/organization/client.mjs +107 -0
  528. package/dist/plugins/organization/client.mjs.map +1 -0
  529. package/dist/plugins/organization/error-codes.d.mts +5 -0
  530. package/dist/plugins/organization/error-codes.mjs +65 -0
  531. package/dist/plugins/organization/error-codes.mjs.map +1 -0
  532. package/dist/plugins/organization/has-permission.mjs +35 -0
  533. package/dist/plugins/organization/has-permission.mjs.map +1 -0
  534. package/dist/plugins/organization/index.d.mts +5 -0
  535. package/dist/plugins/organization/index.mjs +4 -0
  536. package/dist/plugins/organization/organization.d.mts +252 -0
  537. package/dist/plugins/organization/organization.mjs +428 -0
  538. package/dist/plugins/organization/organization.mjs.map +1 -0
  539. package/dist/plugins/organization/permission.d.mts +26 -0
  540. package/dist/plugins/organization/permission.mjs +16 -0
  541. package/dist/plugins/organization/permission.mjs.map +1 -0
  542. package/dist/plugins/organization/routes/crud-access-control.d.mts +11 -0
  543. package/dist/plugins/organization/routes/crud-access-control.mjs +656 -0
  544. package/dist/plugins/organization/routes/crud-access-control.mjs.map +1 -0
  545. package/dist/plugins/organization/routes/crud-invites.d.mts +16 -0
  546. package/dist/plugins/organization/routes/crud-invites.mjs +555 -0
  547. package/dist/plugins/organization/routes/crud-invites.mjs.map +1 -0
  548. package/dist/plugins/organization/routes/crud-members.d.mts +13 -0
  549. package/dist/plugins/organization/routes/crud-members.mjs +473 -0
  550. package/dist/plugins/organization/routes/crud-members.mjs.map +1 -0
  551. package/dist/plugins/organization/routes/crud-org.d.mts +13 -0
  552. package/dist/plugins/organization/routes/crud-org.mjs +447 -0
  553. package/dist/plugins/organization/routes/crud-org.mjs.map +1 -0
  554. package/dist/plugins/organization/routes/crud-team.d.mts +15 -0
  555. package/dist/plugins/organization/routes/crud-team.mjs +676 -0
  556. package/dist/plugins/organization/routes/crud-team.mjs.map +1 -0
  557. package/dist/plugins/organization/schema.d.mts +376 -0
  558. package/dist/plugins/organization/schema.mjs +68 -0
  559. package/dist/plugins/organization/schema.mjs.map +1 -0
  560. package/dist/plugins/organization/types.d.mts +733 -0
  561. package/dist/plugins/phone-number/client.d.mts +8 -0
  562. package/dist/plugins/phone-number/client.mjs +20 -0
  563. package/dist/plugins/phone-number/client.mjs.map +1 -0
  564. package/dist/plugins/phone-number/error-codes.d.mts +5 -0
  565. package/dist/plugins/phone-number/error-codes.mjs +21 -0
  566. package/dist/plugins/phone-number/error-codes.mjs.map +1 -0
  567. package/dist/plugins/phone-number/index.d.mts +14 -0
  568. package/dist/plugins/phone-number/index.mjs +49 -0
  569. package/dist/plugins/phone-number/index.mjs.map +1 -0
  570. package/dist/plugins/phone-number/routes.mjs +459 -0
  571. package/dist/plugins/phone-number/routes.mjs.map +1 -0
  572. package/dist/plugins/phone-number/schema.d.mts +5 -0
  573. package/dist/plugins/phone-number/schema.mjs +20 -0
  574. package/dist/plugins/phone-number/schema.mjs.map +1 -0
  575. package/dist/plugins/phone-number/types.d.mts +118 -0
  576. package/dist/plugins/siwe/client.d.mts +5 -0
  577. package/dist/plugins/siwe/client.mjs +11 -0
  578. package/dist/plugins/siwe/client.mjs.map +1 -0
  579. package/dist/plugins/siwe/error-codes.mjs +13 -0
  580. package/dist/plugins/siwe/error-codes.mjs.map +1 -0
  581. package/dist/plugins/siwe/index.d.mts +26 -0
  582. package/dist/plugins/siwe/index.mjs +261 -0
  583. package/dist/plugins/siwe/index.mjs.map +1 -0
  584. package/dist/plugins/siwe/schema.d.mts +5 -0
  585. package/dist/plugins/siwe/schema.mjs +32 -0
  586. package/dist/plugins/siwe/schema.mjs.map +1 -0
  587. package/dist/plugins/siwe/types.d.mts +44 -0
  588. package/dist/plugins/two-factor/backup-codes/index.d.mts +91 -0
  589. package/dist/plugins/two-factor/backup-codes/index.mjs +277 -0
  590. package/dist/plugins/two-factor/backup-codes/index.mjs.map +1 -0
  591. package/dist/plugins/two-factor/client.d.mts +17 -0
  592. package/dist/plugins/two-factor/client.mjs +37 -0
  593. package/dist/plugins/two-factor/client.mjs.map +1 -0
  594. package/dist/plugins/two-factor/constant.mjs +8 -0
  595. package/dist/plugins/two-factor/constant.mjs.map +1 -0
  596. package/dist/plugins/two-factor/error-code.d.mts +5 -0
  597. package/dist/plugins/two-factor/error-code.mjs +18 -0
  598. package/dist/plugins/two-factor/error-code.mjs.map +1 -0
  599. package/dist/plugins/two-factor/index.d.mts +19 -0
  600. package/dist/plugins/two-factor/index.mjs +207 -0
  601. package/dist/plugins/two-factor/index.mjs.map +1 -0
  602. package/dist/plugins/two-factor/otp/index.d.mts +96 -0
  603. package/dist/plugins/two-factor/otp/index.mjs +199 -0
  604. package/dist/plugins/two-factor/otp/index.mjs.map +1 -0
  605. package/dist/plugins/two-factor/schema.d.mts +5 -0
  606. package/dist/plugins/two-factor/schema.mjs +36 -0
  607. package/dist/plugins/two-factor/schema.mjs.map +1 -0
  608. package/dist/plugins/two-factor/totp/index.d.mts +81 -0
  609. package/dist/plugins/two-factor/totp/index.mjs +157 -0
  610. package/dist/plugins/two-factor/totp/index.mjs.map +1 -0
  611. package/dist/plugins/two-factor/types.d.mts +65 -0
  612. package/dist/plugins/two-factor/utils.mjs +12 -0
  613. package/dist/plugins/two-factor/utils.mjs.map +1 -0
  614. package/dist/plugins/two-factor/verify-two-factor.mjs +76 -0
  615. package/dist/plugins/two-factor/verify-two-factor.mjs.map +1 -0
  616. package/dist/plugins/username/client.d.mts +7 -0
  617. package/dist/plugins/username/client.mjs +18 -0
  618. package/dist/plugins/username/client.mjs.map +1 -0
  619. package/dist/plugins/username/error-codes.d.mts +5 -0
  620. package/dist/plugins/username/error-codes.mjs +17 -0
  621. package/dist/plugins/username/error-codes.mjs.map +1 -0
  622. package/dist/plugins/username/index.d.mts +74 -0
  623. package/dist/plugins/username/index.mjs +237 -0
  624. package/dist/plugins/username/index.mjs.map +1 -0
  625. package/dist/plugins/username/schema.d.mts +9 -0
  626. package/dist/plugins/username/schema.mjs +26 -0
  627. package/dist/plugins/username/schema.mjs.map +1 -0
  628. package/dist/social-providers/index.d.mts +1 -0
  629. package/dist/social-providers/index.mjs +3 -0
  630. package/dist/state.d.mts +42 -0
  631. package/dist/state.mjs +107 -0
  632. package/dist/state.mjs.map +1 -0
  633. package/dist/test-utils/headers.d.mts +9 -0
  634. package/dist/test-utils/headers.mjs +24 -0
  635. package/dist/test-utils/headers.mjs.map +1 -0
  636. package/dist/test-utils/index.d.mts +3 -0
  637. package/dist/test-utils/index.mjs +4 -0
  638. package/dist/test-utils/test-instance.d.mts +181 -0
  639. package/dist/test-utils/test-instance.mjs +210 -0
  640. package/dist/test-utils/test-instance.mjs.map +1 -0
  641. package/dist/types/adapter.d.mts +24 -0
  642. package/dist/types/api.d.mts +62 -0
  643. package/dist/types/auth.d.mts +30 -0
  644. package/dist/types/helper.d.mts +21 -0
  645. package/dist/types/index.d.mts +11 -0
  646. package/dist/types/index.mjs +1 -0
  647. package/dist/types/models.d.mts +17 -0
  648. package/dist/types/plugins.d.mts +16 -0
  649. package/dist/utils/boolean.mjs +8 -0
  650. package/dist/utils/boolean.mjs.map +1 -0
  651. package/dist/utils/constants.mjs +6 -0
  652. package/dist/utils/constants.mjs.map +1 -0
  653. package/dist/utils/date.mjs +8 -0
  654. package/dist/utils/date.mjs.map +1 -0
  655. package/dist/utils/get-request-ip.d.mts +7 -0
  656. package/dist/utils/get-request-ip.mjs +23 -0
  657. package/dist/utils/get-request-ip.mjs.map +1 -0
  658. package/dist/utils/hashing.mjs +21 -0
  659. package/dist/utils/hashing.mjs.map +1 -0
  660. package/dist/utils/hide-metadata.d.mts +7 -0
  661. package/dist/utils/hide-metadata.mjs +6 -0
  662. package/dist/utils/hide-metadata.mjs.map +1 -0
  663. package/dist/utils/index.d.mts +3 -0
  664. package/dist/utils/index.mjs +5 -0
  665. package/dist/utils/is-api-error.d.mts +7 -0
  666. package/dist/utils/is-api-error.mjs +11 -0
  667. package/dist/utils/is-api-error.mjs.map +1 -0
  668. package/dist/utils/is-atom.mjs +8 -0
  669. package/dist/utils/is-atom.mjs.map +1 -0
  670. package/dist/utils/is-promise.mjs +8 -0
  671. package/dist/utils/is-promise.mjs.map +1 -0
  672. package/dist/utils/middleware-response.mjs +6 -0
  673. package/dist/utils/middleware-response.mjs.map +1 -0
  674. package/dist/utils/password.mjs +26 -0
  675. package/dist/utils/password.mjs.map +1 -0
  676. package/dist/utils/plugin-helper.mjs +17 -0
  677. package/dist/utils/plugin-helper.mjs.map +1 -0
  678. package/dist/utils/shim.mjs +24 -0
  679. package/dist/utils/shim.mjs.map +1 -0
  680. package/dist/utils/time.d.mts +49 -0
  681. package/dist/utils/time.mjs +100 -0
  682. package/dist/utils/time.mjs.map +1 -0
  683. package/dist/utils/url.mjs +92 -0
  684. package/dist/utils/url.mjs.map +1 -0
  685. package/dist/utils/wildcard.mjs +108 -0
  686. package/dist/utils/wildcard.mjs.map +1 -0
  687. package/package.json +601 -0
@@ -0,0 +1,8 @@
1
+ import { PHONE_NUMBER_ERROR_CODES } from "./error-codes.mjs";
2
+ import { PhoneNumberOptions, UserWithPhoneNumber } from "./types.mjs";
3
+
4
+ //#region src/plugins/phone-number/client.d.ts
5
+ declare const phoneNumberClient: () => BetterAuthClientPlugin;
6
+ //#endregion
7
+ export { phoneNumberClient };
8
+ //# sourceMappingURL=client.d.mts.map
@@ -0,0 +1,20 @@
1
+ import { PHONE_NUMBER_ERROR_CODES } from "./error-codes.mjs";
2
+
3
+ //#region src/plugins/phone-number/client.ts
4
+ const phoneNumberClient = () => {
5
+ return {
6
+ id: "phoneNumber",
7
+ $InferServerPlugin: {},
8
+ atomListeners: [{
9
+ matcher(path) {
10
+ return path === "/phone-number/update" || path === "/phone-number/verify" || path === "/sign-in/phone-number";
11
+ },
12
+ signal: "$sessionSignal"
13
+ }],
14
+ $ERROR_CODES: PHONE_NUMBER_ERROR_CODES
15
+ };
16
+ };
17
+
18
+ //#endregion
19
+ export { phoneNumberClient };
20
+ //# sourceMappingURL=client.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.mjs","names":[],"sources":["../../../src/plugins/phone-number/client.ts"],"sourcesContent":["import type { BetterAuthClientPlugin } from \"@better-auth/core\";\nimport type { phoneNumber } from \".\";\n\nimport { PHONE_NUMBER_ERROR_CODES } from \"./error-codes\";\n\nexport * from \"./error-codes\";\n\nexport const phoneNumberClient = () => {\n\treturn {\n\t\tid: \"phoneNumber\",\n\t\t$InferServerPlugin: {} as ReturnType<typeof phoneNumber>,\n\t\tatomListeners: [\n\t\t\t{\n\t\t\t\tmatcher(path) {\n\t\t\t\t\treturn (\n\t\t\t\t\t\tpath === \"/phone-number/update\" ||\n\t\t\t\t\t\tpath === \"/phone-number/verify\" ||\n\t\t\t\t\t\tpath === \"/sign-in/phone-number\"\n\t\t\t\t\t);\n\t\t\t\t},\n\t\t\t\tsignal: \"$sessionSignal\",\n\t\t\t},\n\t\t],\n\t\t$ERROR_CODES: PHONE_NUMBER_ERROR_CODES,\n\t} satisfies BetterAuthClientPlugin;\n};\n\nexport type * from \"./types\";\n"],"mappings":";;;AAOA,MAAa,0BAA0B;AACtC,QAAO;EACN,IAAI;EACJ,oBAAoB,EAAE;EACtB,eAAe,CACd;GACC,QAAQ,MAAM;AACb,WACC,SAAS,0BACT,SAAS,0BACT,SAAS;;GAGX,QAAQ;GACR,CACD;EACD,cAAc;EACd"}
@@ -0,0 +1,5 @@
1
+ //#region src/plugins/phone-number/error-codes.d.ts
2
+ declare const PHONE_NUMBER_ERROR_CODES: any;
3
+ //#endregion
4
+ export { PHONE_NUMBER_ERROR_CODES };
5
+ //# sourceMappingURL=error-codes.d.mts.map
@@ -0,0 +1,21 @@
1
+ import { defineErrorCodes } from "@better-auth/core/utils/error-codes";
2
+
3
+ //#region src/plugins/phone-number/error-codes.ts
4
+ const PHONE_NUMBER_ERROR_CODES = defineErrorCodes({
5
+ INVALID_PHONE_NUMBER: "Invalid phone number",
6
+ PHONE_NUMBER_EXIST: "Phone number already exists",
7
+ PHONE_NUMBER_NOT_EXIST: "phone number isn't registered",
8
+ INVALID_PHONE_NUMBER_OR_PASSWORD: "Invalid phone number or password",
9
+ UNEXPECTED_ERROR: "Unexpected error",
10
+ OTP_NOT_FOUND: "OTP not found",
11
+ OTP_EXPIRED: "OTP expired",
12
+ INVALID_OTP: "Invalid OTP",
13
+ PHONE_NUMBER_NOT_VERIFIED: "Phone number not verified",
14
+ PHONE_NUMBER_CANNOT_BE_UPDATED: "Phone number cannot be updated",
15
+ SEND_OTP_NOT_IMPLEMENTED: "sendOTP not implemented",
16
+ TOO_MANY_ATTEMPTS: "Too many attempts"
17
+ });
18
+
19
+ //#endregion
20
+ export { PHONE_NUMBER_ERROR_CODES };
21
+ //# sourceMappingURL=error-codes.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error-codes.mjs","names":[],"sources":["../../../src/plugins/phone-number/error-codes.ts"],"sourcesContent":["import { defineErrorCodes } from \"@better-auth/core/utils/error-codes\";\n\nexport const PHONE_NUMBER_ERROR_CODES = defineErrorCodes({\n\tINVALID_PHONE_NUMBER: \"Invalid phone number\",\n\tPHONE_NUMBER_EXIST: \"Phone number already exists\",\n\tPHONE_NUMBER_NOT_EXIST: \"phone number isn't registered\",\n\tINVALID_PHONE_NUMBER_OR_PASSWORD: \"Invalid phone number or password\",\n\tUNEXPECTED_ERROR: \"Unexpected error\",\n\tOTP_NOT_FOUND: \"OTP not found\",\n\tOTP_EXPIRED: \"OTP expired\",\n\tINVALID_OTP: \"Invalid OTP\",\n\tPHONE_NUMBER_NOT_VERIFIED: \"Phone number not verified\",\n\tPHONE_NUMBER_CANNOT_BE_UPDATED: \"Phone number cannot be updated\",\n\tSEND_OTP_NOT_IMPLEMENTED: \"sendOTP not implemented\",\n\tTOO_MANY_ATTEMPTS: \"Too many attempts\",\n});\n"],"mappings":";;;AAEA,MAAa,2BAA2B,iBAAiB;CACxD,sBAAsB;CACtB,oBAAoB;CACpB,wBAAwB;CACxB,kCAAkC;CAClC,kBAAkB;CAClB,eAAe;CACf,aAAa;CACb,aAAa;CACb,2BAA2B;CAC3B,gCAAgC;CAChC,0BAA0B;CAC1B,mBAAmB;CACnB,CAAC"}
@@ -0,0 +1,14 @@
1
+ import { PhoneNumberOptions, UserWithPhoneNumber } from "./types.mjs";
2
+
3
+ //#region src/plugins/phone-number/index.d.ts
4
+ declare module "@better-auth/core" {
5
+ interface BetterAuthPluginRegistry<AuthOptions, Options> {
6
+ "phone-number": {
7
+ creator: typeof phoneNumber;
8
+ };
9
+ }
10
+ }
11
+ declare const phoneNumber: (options?: PhoneNumberOptions | undefined) => BetterAuthPlugin;
12
+ //#endregion
13
+ export { type PhoneNumberOptions, type UserWithPhoneNumber, phoneNumber };
14
+ //# sourceMappingURL=index.d.mts.map
@@ -0,0 +1,49 @@
1
+ import { mergeSchema } from "../../db/schema.mjs";
2
+ import { PHONE_NUMBER_ERROR_CODES } from "./error-codes.mjs";
3
+ import { requestPasswordResetPhoneNumber, resetPasswordPhoneNumber, sendPhoneNumberOTP, signInPhoneNumber, verifyPhoneNumber } from "./routes.mjs";
4
+ import { schema } from "./schema.mjs";
5
+ import { APIError } from "@better-auth/core/error";
6
+ import { createAuthMiddleware } from "@better-auth/core/api";
7
+
8
+ //#region src/plugins/phone-number/index.ts
9
+ const phoneNumber = (options) => {
10
+ const opts = {
11
+ expiresIn: options?.expiresIn || 300,
12
+ otpLength: options?.otpLength || 6,
13
+ ...options,
14
+ phoneNumber: "phoneNumber",
15
+ phoneNumberVerified: "phoneNumberVerified",
16
+ code: "code",
17
+ createdAt: "createdAt"
18
+ };
19
+ return {
20
+ id: "phone-number",
21
+ hooks: { before: [{
22
+ matcher: (ctx) => ctx.path === "/update-user" && "phoneNumber" in ctx.body,
23
+ handler: createAuthMiddleware(async (_ctx) => {
24
+ throw APIError.from("BAD_REQUEST", PHONE_NUMBER_ERROR_CODES.PHONE_NUMBER_CANNOT_BE_UPDATED);
25
+ })
26
+ }] },
27
+ endpoints: {
28
+ signInPhoneNumber: signInPhoneNumber(opts),
29
+ sendPhoneNumberOTP: sendPhoneNumberOTP(opts),
30
+ verifyPhoneNumber: verifyPhoneNumber(opts),
31
+ requestPasswordResetPhoneNumber: requestPasswordResetPhoneNumber(opts),
32
+ resetPasswordPhoneNumber: resetPasswordPhoneNumber(opts)
33
+ },
34
+ schema: mergeSchema(schema, options?.schema),
35
+ rateLimit: [{
36
+ pathMatcher(path) {
37
+ return path.startsWith("/phone-number");
38
+ },
39
+ window: 60 * 1e3,
40
+ max: 10
41
+ }],
42
+ options,
43
+ $ERROR_CODES: PHONE_NUMBER_ERROR_CODES
44
+ };
45
+ };
46
+
47
+ //#endregion
48
+ export { phoneNumber };
49
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../../../src/plugins/phone-number/index.ts"],"sourcesContent":["import type { BetterAuthPlugin } from \"@better-auth/core\";\nimport { createAuthMiddleware } from \"@better-auth/core/api\";\nimport { APIError } from \"@better-auth/core/error\";\nimport { mergeSchema } from \"../../db/schema\";\nimport { PHONE_NUMBER_ERROR_CODES } from \"./error-codes\";\nimport type { RequiredPhoneNumberOptions } from \"./routes\";\nimport {\n\trequestPasswordResetPhoneNumber,\n\tresetPasswordPhoneNumber,\n\tsendPhoneNumberOTP,\n\tsignInPhoneNumber,\n\tverifyPhoneNumber,\n} from \"./routes\";\nimport { schema } from \"./schema\";\nimport type { PhoneNumberOptions, UserWithPhoneNumber } from \"./types\";\n\nexport type { PhoneNumberOptions, UserWithPhoneNumber };\n\ndeclare module \"@better-auth/core\" {\n\tinterface BetterAuthPluginRegistry<AuthOptions, Options> {\n\t\t\"phone-number\": {\n\t\t\tcreator: typeof phoneNumber;\n\t\t};\n\t}\n}\n\nexport const phoneNumber = (options?: PhoneNumberOptions | undefined) => {\n\tconst opts = {\n\t\texpiresIn: options?.expiresIn || 300,\n\t\totpLength: options?.otpLength || 6,\n\t\t...options,\n\t\tphoneNumber: \"phoneNumber\",\n\t\tphoneNumberVerified: \"phoneNumberVerified\",\n\t\tcode: \"code\",\n\t\tcreatedAt: \"createdAt\",\n\t};\n\n\treturn {\n\t\tid: \"phone-number\",\n\t\thooks: {\n\t\t\tbefore: [\n\t\t\t\t{\n\t\t\t\t\t// Stop any requests attempting to update the user's phone number\n\t\t\t\t\tmatcher: (ctx) =>\n\t\t\t\t\t\tctx.path === \"/update-user\" && \"phoneNumber\" in ctx.body,\n\t\t\t\t\thandler: createAuthMiddleware(async (_ctx) => {\n\t\t\t\t\t\tthrow APIError.from(\n\t\t\t\t\t\t\t\"BAD_REQUEST\",\n\t\t\t\t\t\t\tPHONE_NUMBER_ERROR_CODES.PHONE_NUMBER_CANNOT_BE_UPDATED,\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\tendpoints: {\n\t\t\tsignInPhoneNumber: signInPhoneNumber(opts as RequiredPhoneNumberOptions),\n\t\t\tsendPhoneNumberOTP: sendPhoneNumberOTP(\n\t\t\t\topts as RequiredPhoneNumberOptions,\n\t\t\t),\n\t\t\tverifyPhoneNumber: verifyPhoneNumber(opts as RequiredPhoneNumberOptions),\n\t\t\trequestPasswordResetPhoneNumber: requestPasswordResetPhoneNumber(\n\t\t\t\topts as RequiredPhoneNumberOptions,\n\t\t\t),\n\t\t\tresetPasswordPhoneNumber: resetPasswordPhoneNumber(\n\t\t\t\topts as RequiredPhoneNumberOptions,\n\t\t\t),\n\t\t},\n\t\tschema: mergeSchema(schema, options?.schema),\n\t\trateLimit: [\n\t\t\t{\n\t\t\t\tpathMatcher(path) {\n\t\t\t\t\treturn path.startsWith(\"/phone-number\");\n\t\t\t\t},\n\t\t\t\twindow: 60 * 1000,\n\t\t\t\tmax: 10,\n\t\t\t},\n\t\t],\n\t\toptions,\n\t\t$ERROR_CODES: PHONE_NUMBER_ERROR_CODES,\n\t} satisfies BetterAuthPlugin;\n};\n"],"mappings":";;;;;;;;AA0BA,MAAa,eAAe,YAA6C;CACxE,MAAM,OAAO;EACZ,WAAW,SAAS,aAAa;EACjC,WAAW,SAAS,aAAa;EACjC,GAAG;EACH,aAAa;EACb,qBAAqB;EACrB,MAAM;EACN,WAAW;EACX;AAED,QAAO;EACN,IAAI;EACJ,OAAO,EACN,QAAQ,CACP;GAEC,UAAU,QACT,IAAI,SAAS,kBAAkB,iBAAiB,IAAI;GACrD,SAAS,qBAAqB,OAAO,SAAS;AAC7C,UAAM,SAAS,KACd,eACA,yBAAyB,+BACzB;KACA;GACF,CACD,EACD;EACD,WAAW;GACV,mBAAmB,kBAAkB,KAAmC;GACxE,oBAAoB,mBACnB,KACA;GACD,mBAAmB,kBAAkB,KAAmC;GACxE,iCAAiC,gCAChC,KACA;GACD,0BAA0B,yBACzB,KACA;GACD;EACD,QAAQ,YAAY,QAAQ,SAAS,OAAO;EAC5C,WAAW,CACV;GACC,YAAY,MAAM;AACjB,WAAO,KAAK,WAAW,gBAAgB;;GAExC,QAAQ,KAAK;GACb,KAAK;GACL,CACD;EACD;EACA,cAAc;EACd"}
@@ -0,0 +1,459 @@
1
+ import { generateRandomString } from "../../crypto/random.mjs";
2
+ import { parseUserOutput } from "../../db/schema.mjs";
3
+ import { getDate } from "../../utils/date.mjs";
4
+ import { setSessionCookie } from "../../cookies/index.mjs";
5
+ import { getSessionFromCtx } from "../../api/routes/session.mjs";
6
+ import "../../api/index.mjs";
7
+ import { PHONE_NUMBER_ERROR_CODES } from "./error-codes.mjs";
8
+ import { APIError, BASE_ERROR_CODES } from "@better-auth/core/error";
9
+ import { createAuthEndpoint } from "@better-auth/core/api";
10
+ import * as z from "zod";
11
+
12
+ //#region src/plugins/phone-number/routes.ts
13
+ const signInPhoneNumberBodySchema = z.object({
14
+ phoneNumber: z.string().meta({ description: "Phone number to sign in. Eg: \"+1234567890\"" }),
15
+ password: z.string().meta({ description: "Password to use for sign in." }),
16
+ rememberMe: z.boolean().meta({ description: "Remember the session. Eg: true" }).optional()
17
+ });
18
+ /**
19
+ * ### Endpoint
20
+ *
21
+ * POST `/sign-in/phone-number`
22
+ *
23
+ * ### API Methods
24
+ *
25
+ * **server:**
26
+ * `auth.api.signInPhoneNumber`
27
+ *
28
+ * **client:**
29
+ * `authClient.signIn.phoneNumber`
30
+ *
31
+ * @see [Read our docs to learn more.](https://better-auth.com/docs/plugins/phone-number#api-method-sign-in-phone-number)
32
+ */
33
+ const signInPhoneNumber = (opts) => createAuthEndpoint("/sign-in/phone-number", {
34
+ method: "POST",
35
+ body: signInPhoneNumberBodySchema,
36
+ metadata: { openapi: {
37
+ summary: "Sign in with phone number",
38
+ description: "Use this endpoint to sign in with phone number",
39
+ responses: {
40
+ 200: {
41
+ description: "Success",
42
+ content: { "application/json": { schema: {
43
+ type: "object",
44
+ properties: {
45
+ user: { $ref: "#/components/schemas/User" },
46
+ session: { $ref: "#/components/schemas/Session" }
47
+ }
48
+ } } }
49
+ },
50
+ 400: { description: "Invalid phone number or password" }
51
+ }
52
+ } }
53
+ }, async (ctx) => {
54
+ const { password, phoneNumber } = ctx.body;
55
+ if (opts.phoneNumberValidator) {
56
+ if (!await opts.phoneNumberValidator(ctx.body.phoneNumber)) throw APIError.from("BAD_REQUEST", PHONE_NUMBER_ERROR_CODES.INVALID_PHONE_NUMBER);
57
+ }
58
+ const user = await ctx.context.adapter.findOne({
59
+ model: "user",
60
+ where: [{
61
+ field: "phoneNumber",
62
+ value: phoneNumber
63
+ }]
64
+ });
65
+ if (!user) throw APIError.from("UNAUTHORIZED", PHONE_NUMBER_ERROR_CODES.INVALID_PHONE_NUMBER_OR_PASSWORD);
66
+ if (opts.requireVerification) {
67
+ if (!user.phoneNumberVerified) {
68
+ const otp = generateOTP(opts.otpLength);
69
+ await ctx.context.internalAdapter.createVerificationValue({
70
+ value: otp,
71
+ identifier: phoneNumber,
72
+ expiresAt: getDate(opts.expiresIn, "sec")
73
+ });
74
+ if (opts.sendOTP) await ctx.context.runInBackgroundOrAwait(opts.sendOTP({
75
+ phoneNumber,
76
+ code: otp
77
+ }, ctx));
78
+ throw APIError.from("UNAUTHORIZED", PHONE_NUMBER_ERROR_CODES.PHONE_NUMBER_NOT_VERIFIED);
79
+ }
80
+ }
81
+ const credentialAccount = (await ctx.context.internalAdapter.findAccountByUserId(user.id)).find((a) => a.providerId === "credential");
82
+ if (!credentialAccount) {
83
+ ctx.context.logger.error("Credential account not found", { phoneNumber });
84
+ throw APIError.from("UNAUTHORIZED", PHONE_NUMBER_ERROR_CODES.INVALID_PHONE_NUMBER_OR_PASSWORD);
85
+ }
86
+ const currentPassword = credentialAccount?.password;
87
+ if (!currentPassword) {
88
+ ctx.context.logger.error("Password not found", { phoneNumber });
89
+ throw APIError.from("UNAUTHORIZED", PHONE_NUMBER_ERROR_CODES.UNEXPECTED_ERROR);
90
+ }
91
+ if (!await ctx.context.password.verify({
92
+ hash: currentPassword,
93
+ password
94
+ })) {
95
+ ctx.context.logger.error("Invalid password");
96
+ throw APIError.from("UNAUTHORIZED", PHONE_NUMBER_ERROR_CODES.INVALID_PHONE_NUMBER_OR_PASSWORD);
97
+ }
98
+ const session = await ctx.context.internalAdapter.createSession(user.id, ctx.body.rememberMe === false);
99
+ if (!session) {
100
+ ctx.context.logger.error("Failed to create session");
101
+ throw APIError.from("UNAUTHORIZED", BASE_ERROR_CODES.FAILED_TO_CREATE_SESSION);
102
+ }
103
+ await setSessionCookie(ctx, {
104
+ session,
105
+ user
106
+ }, ctx.body.rememberMe === false);
107
+ return ctx.json({
108
+ token: session.token,
109
+ user: parseUserOutput(ctx.context.options, user)
110
+ });
111
+ });
112
+ const sendPhoneNumberOTPBodySchema = z.object({ phoneNumber: z.string().meta({ description: "Phone number to send OTP. Eg: \"+1234567890\"" }) });
113
+ /**
114
+ * ### Endpoint
115
+ *
116
+ * POST `/phone-number/send-otp`
117
+ *
118
+ * ### API Methods
119
+ *
120
+ * **server:**
121
+ * `auth.api.sendPhoneNumberOTP`
122
+ *
123
+ * **client:**
124
+ * `authClient.phoneNumber.sendOtp`
125
+ *
126
+ * @see [Read our docs to learn more.](https://better-auth.com/docs/plugins/phone-number#api-method-phone-number-send-otp)
127
+ */
128
+ const sendPhoneNumberOTP = (opts) => createAuthEndpoint("/phone-number/send-otp", {
129
+ method: "POST",
130
+ body: sendPhoneNumberOTPBodySchema,
131
+ metadata: { openapi: {
132
+ summary: "Send OTP to phone number",
133
+ description: "Use this endpoint to send OTP to phone number",
134
+ responses: { 200: {
135
+ description: "Success",
136
+ content: { "application/json": { schema: {
137
+ type: "object",
138
+ properties: { message: { type: "string" } }
139
+ } } }
140
+ } }
141
+ } }
142
+ }, async (ctx) => {
143
+ if (!opts?.sendOTP) {
144
+ ctx.context.logger.warn("sendOTP not implemented");
145
+ throw APIError.from("NOT_IMPLEMENTED", PHONE_NUMBER_ERROR_CODES.SEND_OTP_NOT_IMPLEMENTED);
146
+ }
147
+ if (opts.phoneNumberValidator) {
148
+ if (!await opts.phoneNumberValidator(ctx.body.phoneNumber)) throw APIError.from("BAD_REQUEST", PHONE_NUMBER_ERROR_CODES.INVALID_PHONE_NUMBER);
149
+ }
150
+ const code = generateOTP(opts.otpLength);
151
+ await ctx.context.internalAdapter.createVerificationValue({
152
+ value: `${code}:0`,
153
+ identifier: ctx.body.phoneNumber,
154
+ expiresAt: getDate(opts.expiresIn, "sec")
155
+ });
156
+ await ctx.context.runInBackgroundOrAwait(opts.sendOTP({
157
+ phoneNumber: ctx.body.phoneNumber,
158
+ code
159
+ }, ctx));
160
+ return ctx.json({ message: "code sent" });
161
+ });
162
+ const verifyPhoneNumberBodySchema = z.object({
163
+ phoneNumber: z.string().meta({ description: "Phone number to verify. Eg: \"+1234567890\"" }),
164
+ code: z.string().meta({ description: "OTP code. Eg: \"123456\"" }),
165
+ disableSession: z.boolean().meta({ description: "Disable session creation after verification. Eg: false" }).optional(),
166
+ updatePhoneNumber: z.boolean().meta({ description: "Check if there is a session and update the phone number. Eg: true" }).optional()
167
+ });
168
+ /**
169
+ * ### Endpoint
170
+ *
171
+ * POST `/phone-number/verify`
172
+ *
173
+ * ### API Methods
174
+ *
175
+ * **server:**
176
+ * `auth.api.verifyPhoneNumber`
177
+ *
178
+ * **client:**
179
+ * `authClient.phoneNumber.verify`
180
+ *
181
+ * @see [Read our docs to learn more.](https://better-auth.com/docs/plugins/phone-number#api-method-phone-number-verify)
182
+ */
183
+ const verifyPhoneNumber = (opts) => createAuthEndpoint("/phone-number/verify", {
184
+ method: "POST",
185
+ body: verifyPhoneNumberBodySchema,
186
+ metadata: { openapi: {
187
+ summary: "Verify phone number",
188
+ description: "Use this endpoint to verify phone number",
189
+ responses: {
190
+ "200": {
191
+ description: "Phone number verified successfully",
192
+ content: { "application/json": { schema: {
193
+ type: "object",
194
+ properties: {
195
+ status: {
196
+ type: "boolean",
197
+ description: "Indicates if the verification was successful",
198
+ enum: [true]
199
+ },
200
+ token: {
201
+ type: "string",
202
+ nullable: true,
203
+ description: "Session token if session is created, null if disableSession is true or no session is created"
204
+ },
205
+ user: {
206
+ type: "object",
207
+ nullable: true,
208
+ properties: {
209
+ id: {
210
+ type: "string",
211
+ description: "Unique identifier of the user"
212
+ },
213
+ email: {
214
+ type: "string",
215
+ format: "email",
216
+ nullable: true,
217
+ description: "User's email address"
218
+ },
219
+ emailVerified: {
220
+ type: "boolean",
221
+ nullable: true,
222
+ description: "Whether the email is verified"
223
+ },
224
+ name: {
225
+ type: "string",
226
+ nullable: true,
227
+ description: "User's name"
228
+ },
229
+ image: {
230
+ type: "string",
231
+ format: "uri",
232
+ nullable: true,
233
+ description: "User's profile image URL"
234
+ },
235
+ phoneNumber: {
236
+ type: "string",
237
+ description: "User's phone number"
238
+ },
239
+ phoneNumberVerified: {
240
+ type: "boolean",
241
+ description: "Whether the phone number is verified"
242
+ },
243
+ createdAt: {
244
+ type: "string",
245
+ format: "date-time",
246
+ description: "Timestamp when the user was created"
247
+ },
248
+ updatedAt: {
249
+ type: "string",
250
+ format: "date-time",
251
+ description: "Timestamp when the user was last updated"
252
+ }
253
+ },
254
+ required: [
255
+ "id",
256
+ "phoneNumber",
257
+ "phoneNumberVerified",
258
+ "createdAt",
259
+ "updatedAt"
260
+ ],
261
+ description: "User object with phone number details, null if no user is created or found"
262
+ }
263
+ },
264
+ required: ["status"]
265
+ } } }
266
+ },
267
+ 400: { description: "Invalid OTP" }
268
+ }
269
+ } }
270
+ }, async (ctx) => {
271
+ if (opts?.verifyOTP) {
272
+ if (!await opts.verifyOTP({
273
+ phoneNumber: ctx.body.phoneNumber,
274
+ code: ctx.body.code
275
+ }, ctx)) throw APIError.from("BAD_REQUEST", PHONE_NUMBER_ERROR_CODES.INVALID_OTP);
276
+ const otp = await ctx.context.internalAdapter.findVerificationValue(ctx.body.phoneNumber);
277
+ if (otp) await ctx.context.internalAdapter.deleteVerificationValue(otp.id);
278
+ } else {
279
+ const otp = await ctx.context.internalAdapter.findVerificationValue(ctx.body.phoneNumber);
280
+ if (!otp || otp.expiresAt < /* @__PURE__ */ new Date()) {
281
+ if (otp && otp.expiresAt < /* @__PURE__ */ new Date()) throw APIError.from("BAD_REQUEST", PHONE_NUMBER_ERROR_CODES.OTP_EXPIRED);
282
+ throw APIError.from("BAD_REQUEST", PHONE_NUMBER_ERROR_CODES.OTP_NOT_FOUND);
283
+ }
284
+ const [otpValue, attempts] = otp.value.split(":");
285
+ const allowedAttempts = opts?.allowedAttempts || 3;
286
+ if (attempts && parseInt(attempts) >= allowedAttempts) {
287
+ await ctx.context.internalAdapter.deleteVerificationValue(otp.id);
288
+ throw APIError.from("FORBIDDEN", PHONE_NUMBER_ERROR_CODES.TOO_MANY_ATTEMPTS);
289
+ }
290
+ if (otpValue !== ctx.body.code) {
291
+ await ctx.context.internalAdapter.updateVerificationValue(otp.id, { value: `${otpValue}:${parseInt(attempts || "0") + 1}` });
292
+ throw APIError.from("BAD_REQUEST", PHONE_NUMBER_ERROR_CODES.INVALID_OTP);
293
+ }
294
+ await ctx.context.internalAdapter.deleteVerificationValue(otp.id);
295
+ }
296
+ if (ctx.body.updatePhoneNumber) {
297
+ const session = await getSessionFromCtx(ctx);
298
+ if (!session) throw APIError.from("UNAUTHORIZED", BASE_ERROR_CODES.USER_NOT_FOUND);
299
+ if ((await ctx.context.adapter.findMany({
300
+ model: "user",
301
+ where: [{
302
+ field: "phoneNumber",
303
+ value: ctx.body.phoneNumber
304
+ }]
305
+ })).length) throw APIError.from("BAD_REQUEST", PHONE_NUMBER_ERROR_CODES.PHONE_NUMBER_EXIST);
306
+ const user = await ctx.context.internalAdapter.updateUser(session.user.id, {
307
+ [opts.phoneNumber]: ctx.body.phoneNumber,
308
+ [opts.phoneNumberVerified]: true
309
+ });
310
+ return ctx.json({
311
+ status: true,
312
+ token: session.session.token,
313
+ user: parseUserOutput(ctx.context.options, user)
314
+ });
315
+ }
316
+ let user = await ctx.context.adapter.findOne({
317
+ model: "user",
318
+ where: [{
319
+ value: ctx.body.phoneNumber,
320
+ field: opts.phoneNumber
321
+ }]
322
+ });
323
+ if (!user) {
324
+ if (opts?.signUpOnVerification) {
325
+ user = await ctx.context.internalAdapter.createUser({
326
+ email: opts.signUpOnVerification.getTempEmail(ctx.body.phoneNumber),
327
+ name: opts.signUpOnVerification.getTempName ? opts.signUpOnVerification.getTempName(ctx.body.phoneNumber) : ctx.body.phoneNumber,
328
+ [opts.phoneNumber]: ctx.body.phoneNumber,
329
+ [opts.phoneNumberVerified]: true
330
+ });
331
+ if (!user) throw APIError.from("INTERNAL_SERVER_ERROR", BASE_ERROR_CODES.FAILED_TO_CREATE_USER);
332
+ }
333
+ } else user = await ctx.context.internalAdapter.updateUser(user.id, { [opts.phoneNumberVerified]: true });
334
+ if (!user) throw APIError.from("INTERNAL_SERVER_ERROR", BASE_ERROR_CODES.FAILED_TO_UPDATE_USER);
335
+ await opts?.callbackOnVerification?.({
336
+ phoneNumber: ctx.body.phoneNumber,
337
+ user
338
+ }, ctx);
339
+ if (!ctx.body.disableSession) {
340
+ const session = await ctx.context.internalAdapter.createSession(user.id);
341
+ if (!session) throw APIError.from("INTERNAL_SERVER_ERROR", BASE_ERROR_CODES.FAILED_TO_CREATE_SESSION);
342
+ await setSessionCookie(ctx, {
343
+ session,
344
+ user
345
+ });
346
+ return ctx.json({
347
+ status: true,
348
+ token: session.token,
349
+ user: parseUserOutput(ctx.context.options, user)
350
+ });
351
+ }
352
+ return ctx.json({
353
+ status: true,
354
+ token: null,
355
+ user: parseUserOutput(ctx.context.options, user)
356
+ });
357
+ });
358
+ const requestPasswordResetPhoneNumberBodySchema = z.object({ phoneNumber: z.string() });
359
+ const requestPasswordResetPhoneNumber = (opts) => createAuthEndpoint("/phone-number/request-password-reset", {
360
+ method: "POST",
361
+ body: requestPasswordResetPhoneNumberBodySchema,
362
+ metadata: { openapi: {
363
+ description: "Request OTP for password reset via phone number",
364
+ responses: { "200": {
365
+ description: "OTP sent successfully for password reset",
366
+ content: { "application/json": { schema: {
367
+ type: "object",
368
+ properties: { status: {
369
+ type: "boolean",
370
+ description: "Indicates if the OTP was sent successfully",
371
+ enum: [true]
372
+ } },
373
+ required: ["status"]
374
+ } } }
375
+ } }
376
+ } }
377
+ }, async (ctx) => {
378
+ const user = await ctx.context.adapter.findOne({
379
+ model: "user",
380
+ where: [{
381
+ value: ctx.body.phoneNumber,
382
+ field: opts.phoneNumber
383
+ }]
384
+ });
385
+ const code = generateOTP(opts.otpLength);
386
+ await ctx.context.internalAdapter.createVerificationValue({
387
+ value: `${code}:0`,
388
+ identifier: `${ctx.body.phoneNumber}-request-password-reset`,
389
+ expiresAt: getDate(opts.expiresIn, "sec")
390
+ });
391
+ if (!user) return ctx.json({ status: true });
392
+ if (opts.sendPasswordResetOTP) await ctx.context.runInBackgroundOrAwait(opts.sendPasswordResetOTP({
393
+ phoneNumber: ctx.body.phoneNumber,
394
+ code
395
+ }, ctx));
396
+ return ctx.json({ status: true });
397
+ });
398
+ const resetPasswordPhoneNumberBodySchema = z.object({
399
+ otp: z.string().meta({ description: "The one time password to reset the password. Eg: \"123456\"" }),
400
+ phoneNumber: z.string().meta({ description: "The phone number to the account which intends to reset the password for. Eg: \"+1234567890\"" }),
401
+ newPassword: z.string().meta({ description: `The new password. Eg: "new-and-secure-password"` })
402
+ });
403
+ const resetPasswordPhoneNumber = (opts) => createAuthEndpoint("/phone-number/reset-password", {
404
+ method: "POST",
405
+ body: resetPasswordPhoneNumberBodySchema,
406
+ metadata: { openapi: {
407
+ description: "Reset password using phone number OTP",
408
+ responses: { "200": {
409
+ description: "Password reset successfully",
410
+ content: { "application/json": { schema: {
411
+ type: "object",
412
+ properties: { status: {
413
+ type: "boolean",
414
+ description: "Indicates if the password was reset successfully",
415
+ enum: [true]
416
+ } },
417
+ required: ["status"]
418
+ } } }
419
+ } }
420
+ } }
421
+ }, async (ctx) => {
422
+ const verification = await ctx.context.internalAdapter.findVerificationValue(`${ctx.body.phoneNumber}-request-password-reset`);
423
+ if (!verification) throw APIError.from("BAD_REQUEST", PHONE_NUMBER_ERROR_CODES.OTP_NOT_FOUND);
424
+ if (verification.expiresAt < /* @__PURE__ */ new Date()) throw APIError.from("BAD_REQUEST", PHONE_NUMBER_ERROR_CODES.OTP_EXPIRED);
425
+ const [otpValue, attempts] = verification.value.split(":");
426
+ const allowedAttempts = opts?.allowedAttempts || 3;
427
+ if (attempts && parseInt(attempts) >= allowedAttempts) {
428
+ await ctx.context.internalAdapter.deleteVerificationValue(verification.id);
429
+ throw APIError.from("FORBIDDEN", PHONE_NUMBER_ERROR_CODES.TOO_MANY_ATTEMPTS);
430
+ }
431
+ if (ctx.body.otp !== otpValue) {
432
+ await ctx.context.internalAdapter.updateVerificationValue(verification.id, { value: `${otpValue}:${parseInt(attempts || "0") + 1}` });
433
+ throw APIError.from("BAD_REQUEST", PHONE_NUMBER_ERROR_CODES.INVALID_OTP);
434
+ }
435
+ const user = await ctx.context.adapter.findOne({
436
+ model: "user",
437
+ where: [{
438
+ field: "phoneNumber",
439
+ value: ctx.body.phoneNumber
440
+ }]
441
+ });
442
+ if (!user) throw APIError.from("BAD_REQUEST", PHONE_NUMBER_ERROR_CODES.UNEXPECTED_ERROR);
443
+ const minLength = ctx.context.password.config.minPasswordLength;
444
+ const maxLength = ctx.context.password.config.maxPasswordLength;
445
+ if (ctx.body.newPassword.length < minLength) throw APIError.from("BAD_REQUEST", BASE_ERROR_CODES.PASSWORD_TOO_SHORT);
446
+ if (ctx.body.newPassword.length > maxLength) throw APIError.from("BAD_REQUEST", BASE_ERROR_CODES.PASSWORD_TOO_LONG);
447
+ const hashedPassword = await ctx.context.password.hash(ctx.body.newPassword);
448
+ await ctx.context.internalAdapter.updatePassword(user.id, hashedPassword);
449
+ await ctx.context.internalAdapter.deleteVerificationValue(verification.id);
450
+ if (ctx.context.options.emailAndPassword?.revokeSessionsOnPasswordReset) await ctx.context.internalAdapter.deleteSessions(user.id);
451
+ return ctx.json({ status: true });
452
+ });
453
+ function generateOTP(size) {
454
+ return generateRandomString(size, "0-9");
455
+ }
456
+
457
+ //#endregion
458
+ export { requestPasswordResetPhoneNumber, resetPasswordPhoneNumber, sendPhoneNumberOTP, signInPhoneNumber, verifyPhoneNumber };
459
+ //# sourceMappingURL=routes.mjs.map