@mesob/auth-react 0.3.5 → 0.4.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 (372) hide show
  1. package/dist/chunk-35TCGAW3.js +98 -0
  2. package/dist/chunk-35TCGAW3.js.map +1 -0
  3. package/dist/chunk-3BZC4VVD.js +36 -0
  4. package/dist/chunk-3BZC4VVD.js.map +1 -0
  5. package/dist/chunk-45UCLKH2.js +188 -0
  6. package/dist/chunk-45UCLKH2.js.map +1 -0
  7. package/dist/chunk-55BMNC4S.js +115 -0
  8. package/dist/chunk-55BMNC4S.js.map +1 -0
  9. package/dist/chunk-5F5FZMHE.js +94 -0
  10. package/dist/chunk-5F5FZMHE.js.map +1 -0
  11. package/dist/chunk-5M7I7WNH.js +31 -0
  12. package/dist/chunk-5M7I7WNH.js.map +1 -0
  13. package/dist/chunk-72YRO3A7.js +288 -0
  14. package/dist/chunk-72YRO3A7.js.map +1 -0
  15. package/dist/chunk-7KXTL6NT.js +48 -0
  16. package/dist/chunk-7KXTL6NT.js.map +1 -0
  17. package/dist/chunk-AIMD6R6U.js +466 -0
  18. package/dist/chunk-AIMD6R6U.js.map +1 -0
  19. package/dist/chunk-BGSHXIHI.js +953 -0
  20. package/dist/chunk-BGSHXIHI.js.map +1 -0
  21. package/dist/chunk-BZ42QPXE.js +271 -0
  22. package/dist/chunk-BZ42QPXE.js.map +1 -0
  23. package/dist/chunk-C26NPUPI.js +272 -0
  24. package/dist/chunk-C26NPUPI.js.map +1 -0
  25. package/dist/chunk-C2KFZ57H.js +194 -0
  26. package/dist/chunk-C2KFZ57H.js.map +1 -0
  27. package/dist/chunk-C5ZW7FD2.js +46 -0
  28. package/dist/chunk-C5ZW7FD2.js.map +1 -0
  29. package/dist/chunk-DPH2PHK3.js +32 -0
  30. package/dist/chunk-DPH2PHK3.js.map +1 -0
  31. package/dist/chunk-EQ4346FE.js +139 -0
  32. package/dist/chunk-EQ4346FE.js.map +1 -0
  33. package/dist/chunk-FAHN63DA.js +535 -0
  34. package/dist/chunk-FAHN63DA.js.map +1 -0
  35. package/dist/chunk-FBABIA5J.js +345 -0
  36. package/dist/chunk-FBABIA5J.js.map +1 -0
  37. package/dist/chunk-FFR5UHTS.js +99 -0
  38. package/dist/chunk-FFR5UHTS.js.map +1 -0
  39. package/dist/chunk-FHOLUOOZ.js +164 -0
  40. package/dist/chunk-FHOLUOOZ.js.map +1 -0
  41. package/dist/chunk-G2AW2H36.js +11 -0
  42. package/dist/chunk-G2AW2H36.js.map +1 -0
  43. package/dist/chunk-G7SCXCCM.js +89 -0
  44. package/dist/chunk-G7SCXCCM.js.map +1 -0
  45. package/dist/chunk-GP7GIUI3.js +64 -0
  46. package/dist/chunk-GP7GIUI3.js.map +1 -0
  47. package/dist/chunk-GRT6EBR6.js +93 -0
  48. package/dist/chunk-GRT6EBR6.js.map +1 -0
  49. package/dist/chunk-GXKBVCVS.js +102 -0
  50. package/dist/chunk-GXKBVCVS.js.map +1 -0
  51. package/dist/chunk-HOO2VLNM.js +305 -0
  52. package/dist/chunk-HOO2VLNM.js.map +1 -0
  53. package/dist/chunk-II5MLBSB.js +183 -0
  54. package/dist/chunk-II5MLBSB.js.map +1 -0
  55. package/dist/chunk-ISNNPMF7.js +95 -0
  56. package/dist/chunk-ISNNPMF7.js.map +1 -0
  57. package/dist/chunk-JB6XVST4.js +141 -0
  58. package/dist/chunk-JB6XVST4.js.map +1 -0
  59. package/dist/chunk-JUHBVG5Q.js +303 -0
  60. package/dist/chunk-JUHBVG5Q.js.map +1 -0
  61. package/dist/chunk-JZZJCBAE.js +118 -0
  62. package/dist/chunk-JZZJCBAE.js.map +1 -0
  63. package/dist/chunk-KWG4DSB5.js +55 -0
  64. package/dist/chunk-KWG4DSB5.js.map +1 -0
  65. package/dist/chunk-L4CGIO2I.js +265 -0
  66. package/dist/chunk-L4CGIO2I.js.map +1 -0
  67. package/dist/chunk-LNG736CV.js +19 -0
  68. package/dist/chunk-LNG736CV.js.map +1 -0
  69. package/dist/chunk-LSYKVFJA.js +98 -0
  70. package/dist/chunk-LSYKVFJA.js.map +1 -0
  71. package/dist/chunk-LZR4YUDV.js +107 -0
  72. package/dist/chunk-LZR4YUDV.js.map +1 -0
  73. package/dist/chunk-MELNS4QH.js +255 -0
  74. package/dist/chunk-MELNS4QH.js.map +1 -0
  75. package/dist/chunk-MS2JUZ3N.js +94 -0
  76. package/dist/chunk-MS2JUZ3N.js.map +1 -0
  77. package/dist/chunk-NEO72TMH.js +32 -0
  78. package/dist/chunk-NEO72TMH.js.map +1 -0
  79. package/dist/chunk-NJPNTAAT.js +68 -0
  80. package/dist/chunk-NJPNTAAT.js.map +1 -0
  81. package/dist/chunk-NPW7D2HZ.js +16 -0
  82. package/dist/chunk-NPW7D2HZ.js.map +1 -0
  83. package/dist/chunk-OAN4EXU4.js +310 -0
  84. package/dist/chunk-OAN4EXU4.js.map +1 -0
  85. package/dist/chunk-OFLSINVU.js +138 -0
  86. package/dist/chunk-OFLSINVU.js.map +1 -0
  87. package/dist/chunk-OHIIMUQC.js +286 -0
  88. package/dist/chunk-OHIIMUQC.js.map +1 -0
  89. package/dist/chunk-OQGJX37L.js +239 -0
  90. package/dist/chunk-OQGJX37L.js.map +1 -0
  91. package/dist/chunk-OYHH7HQG.js +65 -0
  92. package/dist/chunk-OYHH7HQG.js.map +1 -0
  93. package/dist/chunk-PSRIZMWJ.js +486 -0
  94. package/dist/chunk-PSRIZMWJ.js.map +1 -0
  95. package/dist/chunk-QNCE2B5O.js +23 -0
  96. package/dist/chunk-QNCE2B5O.js.map +1 -0
  97. package/dist/chunk-RLPZFLAS.js +23 -0
  98. package/dist/chunk-RLPZFLAS.js.map +1 -0
  99. package/dist/chunk-RT5C7IAE.js +38 -0
  100. package/dist/chunk-RT5C7IAE.js.map +1 -0
  101. package/dist/chunk-S3CXCCKL.js +272 -0
  102. package/dist/chunk-S3CXCCKL.js.map +1 -0
  103. package/dist/chunk-SOCZK4CV.js +69 -0
  104. package/dist/chunk-SOCZK4CV.js.map +1 -0
  105. package/dist/chunk-T6P7UHVP.js +34 -0
  106. package/dist/chunk-T6P7UHVP.js.map +1 -0
  107. package/dist/chunk-TFVBER3Y.js +52 -0
  108. package/dist/chunk-TFVBER3Y.js.map +1 -0
  109. package/dist/chunk-UXOZ2TME.js +104 -0
  110. package/dist/chunk-UXOZ2TME.js.map +1 -0
  111. package/dist/chunk-V2W3WPCZ.js +22 -0
  112. package/dist/chunk-V2W3WPCZ.js.map +1 -0
  113. package/dist/chunk-YZ264S2L.js +286 -0
  114. package/dist/chunk-YZ264S2L.js.map +1 -0
  115. package/dist/chunk-ZESFGO3K.js +28 -0
  116. package/dist/chunk-ZESFGO3K.js.map +1 -0
  117. package/dist/chunk-ZG6WFZHX.js +143 -0
  118. package/dist/chunk-ZG6WFZHX.js.map +1 -0
  119. package/dist/components/auth/auth-card.d.ts +3 -6
  120. package/dist/components/auth/auth-card.js +3 -7
  121. package/dist/components/auth/auth-card.js.map +1 -1
  122. package/dist/components/auth/auth-layout.d.ts +3 -6
  123. package/dist/components/auth/auth-layout.js +3 -28
  124. package/dist/components/auth/auth-layout.js.map +1 -1
  125. package/dist/components/auth/countdown.d.ts +2 -5
  126. package/dist/components/auth/countdown.js +5 -130
  127. package/dist/components/auth/countdown.js.map +1 -1
  128. package/dist/components/auth/forgot-password.d.ts +1 -5
  129. package/dist/components/auth/forgot-password.js +6 -361
  130. package/dist/components/auth/forgot-password.js.map +1 -1
  131. package/dist/components/auth/reset-password-form.d.ts +2 -5
  132. package/dist/components/auth/reset-password-form.js +6 -483
  133. package/dist/components/auth/reset-password-form.js.map +1 -1
  134. package/dist/components/auth/set-password.d.ts +6 -0
  135. package/dist/components/auth/set-password.js +13 -0
  136. package/dist/components/auth/set-password.js.map +1 -0
  137. package/dist/components/auth/sign-in.d.ts +2 -5
  138. package/dist/components/auth/sign-in.js +7 -540
  139. package/dist/components/auth/sign-in.js.map +1 -1
  140. package/dist/components/auth/sign-up.d.ts +2 -5
  141. package/dist/components/auth/sign-up.js +6 -509
  142. package/dist/components/auth/sign-up.js.map +1 -1
  143. package/dist/components/auth/verification-form.d.ts +13 -2
  144. package/dist/components/auth/verification-form.js +5 -217
  145. package/dist/components/auth/verification-form.js.map +1 -1
  146. package/dist/components/auth/verify-email.d.ts +2 -5
  147. package/dist/components/auth/verify-email.js +8 -523
  148. package/dist/components/auth/verify-email.js.map +1 -1
  149. package/dist/components/auth/verify-phone.d.ts +2 -5
  150. package/dist/components/auth/verify-phone.js +8 -528
  151. package/dist/components/auth/verify-phone.js.map +1 -1
  152. package/dist/components/authorization/deny.d.ts +8 -0
  153. package/dist/components/authorization/deny.js +9 -0
  154. package/dist/components/authorization/deny.js.map +1 -0
  155. package/dist/components/authorization/grant.d.ts +9 -0
  156. package/dist/components/authorization/grant.js +9 -0
  157. package/dist/components/authorization/grant.js.map +1 -0
  158. package/dist/components/error-boundary.d.ts +6 -10
  159. package/dist/components/error-boundary.js +4 -43
  160. package/dist/components/error-boundary.js.map +1 -1
  161. package/dist/components/iam/permission-selector.d.ts +16 -0
  162. package/dist/components/iam/permission-selector.js +9 -0
  163. package/dist/components/iam/permission-selector.js.map +1 -0
  164. package/dist/components/iam/permissions-page.d.ts +1 -0
  165. package/dist/components/iam/permissions-page.js +10 -0
  166. package/dist/components/iam/permissions-page.js.map +1 -0
  167. package/dist/components/iam/permissions.d.ts +1 -5
  168. package/dist/components/iam/permissions.js +5 -217
  169. package/dist/components/iam/permissions.js.map +1 -1
  170. package/dist/components/iam/role-detail-layout.d.ts +8 -0
  171. package/dist/components/iam/role-detail-layout.js +9 -0
  172. package/dist/components/iam/role-detail-layout.js.map +1 -0
  173. package/dist/components/iam/role-detail-page.d.ts +6 -0
  174. package/dist/components/iam/role-detail-page.js +9 -0
  175. package/dist/components/iam/role-detail-page.js.map +1 -0
  176. package/dist/components/iam/role-permissions-page.d.ts +5 -0
  177. package/dist/components/iam/role-permissions-page.js +10 -0
  178. package/dist/components/iam/role-permissions-page.js.map +1 -0
  179. package/dist/components/iam/roles-page.d.ts +1 -0
  180. package/dist/components/iam/roles-page.js +13 -0
  181. package/dist/components/iam/roles-page.js.map +1 -0
  182. package/dist/components/iam/roles.d.ts +1 -5
  183. package/dist/components/iam/roles.js +5 -215
  184. package/dist/components/iam/roles.js.map +1 -1
  185. package/dist/components/iam/sessions-page.d.ts +1 -0
  186. package/dist/components/iam/sessions-page.js +12 -0
  187. package/dist/components/iam/sessions-page.js.map +1 -0
  188. package/dist/components/iam/sessions.d.ts +1 -5
  189. package/dist/components/iam/sessions.js +5 -198
  190. package/dist/components/iam/sessions.js.map +1 -1
  191. package/dist/components/iam/tenants-page.d.ts +1 -0
  192. package/dist/components/iam/tenants-page.js +13 -0
  193. package/dist/components/iam/tenants-page.js.map +1 -0
  194. package/dist/components/iam/tenants.d.ts +1 -5
  195. package/dist/components/iam/tenants.js +5 -204
  196. package/dist/components/iam/tenants.js.map +1 -1
  197. package/dist/components/iam/users-page.d.ts +1 -0
  198. package/dist/components/iam/users-page.js +13 -0
  199. package/dist/components/iam/users-page.js.map +1 -0
  200. package/dist/components/iam/users.d.ts +1 -5
  201. package/dist/components/iam/users.js +5 -213
  202. package/dist/components/iam/users.js.map +1 -1
  203. package/dist/components/profile/account.d.ts +1 -5
  204. package/dist/components/profile/account.js +5 -61
  205. package/dist/components/profile/account.js.map +1 -1
  206. package/dist/components/profile/change-email-form.d.ts +1 -5
  207. package/dist/components/profile/change-email-form.js +9 -735
  208. package/dist/components/profile/change-email-form.js.map +1 -1
  209. package/dist/components/profile/change-password-form.d.ts +1 -5
  210. package/dist/components/profile/change-password-form.js +3 -262
  211. package/dist/components/profile/change-password-form.js.map +1 -1
  212. package/dist/components/profile/change-phone-form.d.ts +1 -5
  213. package/dist/components/profile/change-phone-form.js +10 -772
  214. package/dist/components/profile/change-phone-form.js.map +1 -1
  215. package/dist/components/profile/change-profile.d.ts +3 -6
  216. package/dist/components/profile/change-profile.js +2 -32
  217. package/dist/components/profile/change-profile.js.map +1 -1
  218. package/dist/components/profile/otp-verification-modal.d.ts +2 -5
  219. package/dist/components/profile/otp-verification-modal.js +6 -266
  220. package/dist/components/profile/otp-verification-modal.js.map +1 -1
  221. package/dist/components/profile/profile-layout.d.ts +4 -0
  222. package/dist/components/profile/profile-layout.js +10 -0
  223. package/dist/components/profile/profile-layout.js.map +1 -0
  224. package/dist/components/profile/request-change-email-form.d.ts +2 -5
  225. package/dist/components/profile/request-change-email-form.js +4 -285
  226. package/dist/components/profile/request-change-email-form.js.map +1 -1
  227. package/dist/components/profile/request-change-phone-form.d.ts +2 -5
  228. package/dist/components/profile/request-change-phone-form.js +5 -323
  229. package/dist/components/profile/request-change-phone-form.js.map +1 -1
  230. package/dist/components/profile/security.d.ts +1 -5
  231. package/dist/components/profile/security.js +15 -1474
  232. package/dist/components/profile/security.js.map +1 -1
  233. package/dist/components/profile/verify-change-email-form.d.ts +2 -5
  234. package/dist/components/profile/verify-change-email-form.js +7 -407
  235. package/dist/components/profile/verify-change-email-form.js.map +1 -1
  236. package/dist/components/profile/verify-change-phone-form.d.ts +2 -5
  237. package/dist/components/profile/verify-change-phone-form.js +7 -411
  238. package/dist/components/profile/verify-change-phone-form.js.map +1 -1
  239. package/dist/components/shared/data-table.d.ts +5 -8
  240. package/dist/components/shared/data-table.js +3 -79
  241. package/dist/components/shared/data-table.js.map +1 -1
  242. package/dist/components/skeletons/auth-form-skeleton.d.ts +1 -5
  243. package/dist/components/skeletons/auth-form-skeleton.js +3 -27
  244. package/dist/components/skeletons/auth-form-skeleton.js.map +1 -1
  245. package/dist/components/skeletons/profile-skeleton.d.ts +1 -5
  246. package/dist/components/skeletons/profile-skeleton.js +3 -28
  247. package/dist/components/skeletons/profile-skeleton.js.map +1 -1
  248. package/dist/components/skeletons/table-skeleton.d.ts +2 -5
  249. package/dist/components/skeletons/table-skeleton.js +3 -34
  250. package/dist/components/skeletons/table-skeleton.js.map +1 -1
  251. package/dist/constants/auth.error.codes.d.ts +5 -0
  252. package/dist/hooks/use-session-cookie-name.d.ts +1 -0
  253. package/dist/hooks/use-translator.d.ts +1 -0
  254. package/dist/index.d.ts +50 -84
  255. package/dist/index.js +160 -3861
  256. package/dist/index.js.map +1 -1
  257. package/dist/lib/query-options.d.ts +10 -0
  258. package/dist/lib/translations.d.ts +3 -0
  259. package/dist/pages/auth/forgot-password.d.ts +3 -0
  260. package/dist/pages/auth/forgot-password.js +22 -0
  261. package/dist/pages/auth/forgot-password.js.map +1 -0
  262. package/dist/pages/auth/layout.d.ts +4 -0
  263. package/dist/pages/auth/layout.js +39 -0
  264. package/dist/pages/auth/layout.js.map +1 -0
  265. package/dist/pages/auth/reset-password.d.ts +7 -0
  266. package/dist/pages/auth/reset-password.js +33 -0
  267. package/dist/pages/auth/reset-password.js.map +1 -0
  268. package/dist/pages/auth/set-password.d.ts +7 -0
  269. package/dist/pages/auth/set-password.js +28 -0
  270. package/dist/pages/auth/set-password.js.map +1 -0
  271. package/dist/pages/auth/sign-in.d.ts +7 -0
  272. package/dist/pages/auth/sign-in.js +26 -0
  273. package/dist/pages/auth/sign-in.js.map +1 -0
  274. package/dist/pages/auth/sign-up.d.ts +7 -0
  275. package/dist/pages/auth/sign-up.js +33 -0
  276. package/dist/pages/auth/sign-up.js.map +1 -0
  277. package/dist/pages/auth/verify-email.d.ts +7 -0
  278. package/dist/pages/auth/verify-email.js +38 -0
  279. package/dist/pages/auth/verify-email.js.map +1 -0
  280. package/dist/pages/auth/verify-phone.d.ts +7 -0
  281. package/dist/pages/auth/verify-phone.js +47 -0
  282. package/dist/pages/auth/verify-phone.js.map +1 -0
  283. package/dist/pages/iam/permissions/_components/permission-card.d.ts +6 -0
  284. package/dist/pages/iam/permissions/_components/permissions-data.d.ts +7 -0
  285. package/dist/pages/iam/permissions/_components/permissions-list.d.ts +14 -0
  286. package/dist/pages/iam/permissions.d.ts +1 -0
  287. package/dist/pages/iam/permissions.js +10 -0
  288. package/dist/pages/iam/permissions.js.map +1 -0
  289. package/dist/pages/iam/role-detail-layout.d.ts +9 -0
  290. package/dist/pages/iam/role-detail-layout.js +18 -0
  291. package/dist/pages/iam/role-detail-layout.js.map +1 -0
  292. package/dist/pages/iam/role-detail.d.ts +9 -0
  293. package/dist/pages/iam/role-detail.js +22 -0
  294. package/dist/pages/iam/role-detail.js.map +1 -0
  295. package/dist/pages/iam/role-permissions.d.ts +9 -0
  296. package/dist/pages/iam/role-permissions.js +23 -0
  297. package/dist/pages/iam/role-permissions.js.map +1 -0
  298. package/dist/pages/iam/role-users.d.ts +9 -0
  299. package/dist/pages/iam/role-users.js +26 -0
  300. package/dist/pages/iam/role-users.js.map +1 -0
  301. package/dist/pages/iam/roles/_components/role-card.d.ts +7 -0
  302. package/dist/pages/iam/roles/_components/role-form.d.ts +9 -0
  303. package/dist/pages/iam/roles/_components/role-selector.d.ts +11 -0
  304. package/dist/pages/iam/roles/_components/roles-data.d.ts +16 -0
  305. package/dist/pages/iam/roles/_components/roles-list.d.ts +15 -0
  306. package/dist/pages/iam/roles/users/_components/role-users-page.d.ts +5 -0
  307. package/dist/pages/iam/roles.d.ts +1 -0
  308. package/dist/pages/iam/roles.js +13 -0
  309. package/dist/pages/iam/roles.js.map +1 -0
  310. package/dist/pages/iam/sessions/_components/session-card.d.ts +6 -0
  311. package/dist/pages/iam/sessions/_components/sessions-data.d.ts +7 -0
  312. package/dist/pages/iam/sessions/_components/sessions-list.d.ts +14 -0
  313. package/dist/pages/iam/sessions.d.ts +1 -0
  314. package/dist/pages/iam/sessions.js +12 -0
  315. package/dist/pages/iam/sessions.js.map +1 -0
  316. package/dist/pages/iam/shared/navigation.d.ts +8 -0
  317. package/dist/pages/iam/shared/page-helpers.d.ts +12 -0
  318. package/dist/pages/iam/tenant-detail.d.ts +7 -0
  319. package/dist/pages/iam/tenant-detail.js +18 -0
  320. package/dist/pages/iam/tenant-detail.js.map +1 -0
  321. package/dist/pages/iam/tenants/_components/tenant-card.d.ts +6 -0
  322. package/dist/pages/iam/tenants/_components/tenant-form.d.ts +9 -0
  323. package/dist/pages/iam/tenants/_components/tenant-selector.d.ts +13 -0
  324. package/dist/pages/iam/tenants/_components/tenants-data.d.ts +12 -0
  325. package/dist/pages/iam/tenants/_components/tenants-list.d.ts +15 -0
  326. package/dist/pages/iam/tenants/tenant-detail-page-content.d.ts +5 -0
  327. package/dist/pages/iam/tenants.d.ts +1 -0
  328. package/dist/pages/iam/tenants.js +13 -0
  329. package/dist/pages/iam/tenants.js.map +1 -0
  330. package/dist/pages/iam/user-activity.d.ts +7 -0
  331. package/dist/pages/iam/user-activity.js +21 -0
  332. package/dist/pages/iam/user-activity.js.map +1 -0
  333. package/dist/pages/iam/user-detail-layout.d.ts +9 -0
  334. package/dist/pages/iam/user-detail-layout.js +18 -0
  335. package/dist/pages/iam/user-detail-layout.js.map +1 -0
  336. package/dist/pages/iam/user-detail.d.ts +7 -0
  337. package/dist/pages/iam/user-detail.js +15 -0
  338. package/dist/pages/iam/user-detail.js.map +1 -0
  339. package/dist/pages/iam/users/_components/bulk-invite-user-form.d.ts +6 -0
  340. package/dist/pages/iam/users/_components/invite-user-form.d.ts +6 -0
  341. package/dist/pages/iam/users/_components/invite-user-shared.d.ts +25 -0
  342. package/dist/pages/iam/users/_components/user-card.d.ts +6 -0
  343. package/dist/pages/iam/users/_components/user-detail-layout-content.d.ts +6 -0
  344. package/dist/pages/iam/users/_components/user-detail-page-content.d.ts +5 -0
  345. package/dist/pages/iam/users/_components/user-form.d.ts +9 -0
  346. package/dist/pages/iam/users/_components/user-selector.d.ts +12 -0
  347. package/dist/pages/iam/users/_components/users-data.d.ts +22 -0
  348. package/dist/pages/iam/users/_components/users-list.d.ts +15 -0
  349. package/dist/pages/iam/users/activity/_components/role-section.d.ts +3 -0
  350. package/dist/pages/iam/users/activity/user-activity-page-content.d.ts +5 -0
  351. package/dist/pages/iam/users.d.ts +1 -0
  352. package/dist/pages/iam/users.js +13 -0
  353. package/dist/pages/iam/users.js.map +1 -0
  354. package/dist/pages/profile/_components/profile-sidebar.d.ts +1 -0
  355. package/dist/pages/profile/account.d.ts +1 -0
  356. package/dist/pages/profile/account.js +33 -0
  357. package/dist/pages/profile/account.js.map +1 -0
  358. package/dist/pages/profile/layout.d.ts +1 -0
  359. package/dist/pages/profile/layout.js +10 -0
  360. package/dist/pages/profile/layout.js.map +1 -0
  361. package/dist/pages/profile/security.d.ts +1 -0
  362. package/dist/pages/profile/security.js +44 -0
  363. package/dist/pages/profile/security.js.map +1 -0
  364. package/dist/provider.d.ts +53 -0
  365. package/dist/types.d.ts +96 -0
  366. package/dist/utils/cookie.d.ts +2 -0
  367. package/dist/utils/custom-fetch.d.ts +2 -0
  368. package/dist/utils/handle-error.d.ts +7 -0
  369. package/dist/utils/normalize-phone.d.ts +1 -0
  370. package/package.json +103 -4
  371. package/dist/types-vcfvnAzQ.d.ts +0 -69
  372. package/dist/verification-form-ipSRTtQB.d.ts +0 -22
@@ -1,1479 +1,20 @@
1
1
  "use client";
2
-
3
- // src/components/profile/change-email-form.tsx
4
2
  import {
5
- Button as Button3,
6
- Collapsible,
7
- CollapsibleContent,
8
- CollapsibleTrigger
9
- } from "@mesob/ui/components";
10
- import { IconChevronDown } from "@tabler/icons-react";
11
- import { useState as useState5 } from "react";
12
-
13
- // src/provider.tsx
14
- import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
15
- import { deepmerge } from "deepmerge-ts";
16
- import createFetchClient from "openapi-fetch";
17
- import createClient from "openapi-react-query";
18
- import { createContext, useContext, useMemo, useState } from "react";
19
-
20
- // src/lib/translations.ts
21
- function createTranslator(messages, namespace) {
22
- return (key, params) => {
23
- const fullKey = namespace ? `${namespace}.${key}` : key;
24
- const keys = fullKey.split(".");
25
- let value = messages;
26
- for (const k of keys) {
27
- if (value && typeof value === "object" && value !== null) {
28
- value = value[k];
29
- } else {
30
- return fullKey;
31
- }
32
- }
33
- if (typeof value !== "string") {
34
- return fullKey;
35
- }
36
- if (params) {
37
- return value.replace(
38
- /\{(\w+)\}/g,
39
- (_, param) => String(params[param] ?? `{${param}}`)
40
- );
41
- }
42
- return value;
43
- };
44
- }
45
-
46
- // src/utils/cookie.ts
47
- var isProduction = typeof process !== "undefined" && process.env.NODE_ENV === "production";
48
-
49
- // src/provider.tsx
50
- import { jsx } from "react/jsx-runtime";
51
- var SessionContext = createContext(null);
52
- var ApiContext = createContext(null);
53
- var ConfigContext = createContext(null);
54
- var queryClient = new QueryClient({
55
- defaultOptions: {
56
- queries: {
57
- refetchOnWindowFocus: false
58
- }
59
- }
60
- });
61
- function useSession() {
62
- const context = useContext(SessionContext);
63
- if (!context) {
64
- throw new Error("useSession must be used within MesobAuthProvider");
65
- }
66
- return context;
67
- }
68
- function useApi() {
69
- const context = useContext(ApiContext);
70
- if (!context) {
71
- throw new Error("useApi must be used within MesobAuthProvider");
72
- }
73
- return context;
74
- }
75
- function useConfig() {
76
- const context = useContext(ConfigContext);
77
- if (!context) {
78
- throw new Error("useConfig must be used within MesobAuthProvider");
79
- }
80
- return context;
81
- }
82
-
83
- // src/components/profile/request-change-email-form.tsx
84
- import { zodResolver } from "@hookform/resolvers/zod";
85
- import { Button, Input, Label, Spinner } from "@mesob/ui/components";
86
- import { IconEye, IconEyeOff } from "@tabler/icons-react";
87
- import { useEffect, useState as useState2 } from "react";
88
- import { useForm } from "react-hook-form";
89
- import { toast } from "sonner";
90
- import { z } from "zod";
91
- import { jsx as jsx2, jsxs } from "react/jsx-runtime";
92
- var emailPasswordSchema = z.object({
93
- email: z.string().email("Invalid email address"),
94
- password: z.string().min(8, "Password must be at least 8 characters").max(128, "Password too long")
95
- });
96
- function isAuthError(error) {
97
- return typeof error === "object" && error !== null && ("code" in error || "message" in error || "name" in error);
98
- }
99
- function getErrorCode(error) {
100
- if (error.code) {
101
- return error.code;
102
- }
103
- if (error.message) {
104
- const upperMessage = error.message.toUpperCase().trim();
105
- const validCodes = [
106
- "USER_NOT_FOUND",
107
- "USER_EXISTS",
108
- "INVALID_PASSWORD",
109
- "VERIFICATION_EXPIRED",
110
- "VERIFICATION_MISMATCH",
111
- "VERIFICATION_NOT_FOUND",
112
- "TOO_MANY_ATTEMPTS",
113
- "UNAUTHORIZED"
114
- ];
115
- if (validCodes.includes(upperMessage)) {
116
- return upperMessage;
117
- }
118
- }
119
- return void 0;
120
- }
121
- function getErrorMessage(error) {
122
- if (isAuthError(error)) {
123
- const errorCode = getErrorCode(error);
124
- switch (errorCode) {
125
- case "USER_EXISTS":
126
- return "This email is already taken. Please use a different email.";
127
- case "VERIFICATION_EXPIRED":
128
- return "Verification code has expired. Please request a new one.";
129
- case "VERIFICATION_MISMATCH":
130
- return "Invalid verification code. Please try again.";
131
- case "VERIFICATION_NOT_FOUND":
132
- return "Verification not found. Please request a new code.";
133
- default:
134
- return error.message || "An error occurred. Please try again.";
135
- }
136
- }
137
- if (error instanceof Error) {
138
- return error.message;
139
- }
140
- return "An error occurred. Please try again.";
141
- }
142
- function RequestChangeEmailForm({
143
- onSuccess,
144
- onCancel,
145
- buttonText
146
- }) {
147
- const { user } = useSession();
148
- const { hooks } = useApi();
149
- const [isSubmitting, setIsSubmitting] = useState2(false);
150
- const [isChecking, setIsChecking] = useState2(true);
151
- const [showPassword, setShowPassword] = useState2(false);
152
- const getPendingAccountChangeQuery = hooks.useQuery(
153
- "get",
154
- "/account-change/pending",
155
- {},
156
- { enabled: false }
157
- );
158
- const verifyPasswordMutation = hooks.useMutation("post", "/password/verify");
159
- const checkUserMutation = hooks.useMutation("post", "/check-account");
160
- const requestEmailVerificationMutation = hooks.useMutation(
161
- "post",
162
- "/email/verification/request"
163
- );
164
- const emailPasswordForm = useForm({
165
- resolver: zodResolver(emailPasswordSchema),
166
- defaultValues: {
167
- email: "",
168
- password: ""
169
- }
170
- });
171
- const {
172
- register,
173
- handleSubmit,
174
- getValues,
175
- setValue,
176
- formState: { errors }
177
- } = emailPasswordForm;
178
- useEffect(() => {
179
- let active = true;
180
- const run = async () => {
181
- try {
182
- const data = await getPendingAccountChangeQuery.refetch();
183
- if (!active) {
184
- return;
185
- }
186
- const accountChange = data.data?.accountChange;
187
- const verificationId = data.data?.verificationId;
188
- if (accountChange?.changeType !== "email") {
189
- setIsChecking(false);
190
- return;
191
- }
192
- if (!accountChange.newEmail) {
193
- setIsChecking(false);
194
- return;
195
- }
196
- if (getValues("email")) {
197
- setIsChecking(false);
198
- return;
199
- }
200
- setValue("email", accountChange.newEmail, { shouldValidate: true });
201
- if (verificationId) {
202
- toast.message("Resuming verification\u2026");
203
- onSuccess(verificationId, accountChange.newEmail);
204
- return;
205
- }
206
- setIsChecking(false);
207
- } catch {
208
- setIsChecking(false);
209
- }
210
- };
211
- run().catch(() => void 0);
212
- return () => {
213
- active = false;
214
- };
215
- }, [getPendingAccountChangeQuery.refetch, getValues, onSuccess, setValue]);
216
- const onEmailPasswordSubmit = async (data) => {
217
- if (!user) {
218
- toast.error("User not found");
219
- return;
220
- }
221
- try {
222
- setIsSubmitting(true);
223
- await verifyPasswordMutation.mutateAsync({
224
- body: { password: data.password }
225
- });
226
- const checkResult = await checkUserMutation.mutateAsync({
227
- body: { identifier: data.email }
228
- });
229
- if (checkResult.data?.exists) {
230
- if (user?.email?.toLowerCase() === data.email.toLowerCase()) {
231
- toast.error("This is already your current email address.");
232
- return;
233
- }
234
- toast.error(
235
- "This email is already taken. Please use a different email."
236
- );
237
- return;
238
- }
239
- const verification = await requestEmailVerificationMutation.mutateAsync({
240
- body: { email: data.email }
241
- });
242
- toast.success("Verification code sent to your email");
243
- onSuccess(verification.data?.verificationId ?? "", data.email);
244
- } catch (error) {
245
- const errorMessage = getErrorMessage(error);
246
- if (isAuthError(error)) {
247
- const errorCode = getErrorCode(error);
248
- if (errorCode === "INVALID_PASSWORD" || errorCode === "USER_NOT_FOUND") {
249
- toast.error("Incorrect password. Please try again.");
250
- return;
251
- }
252
- }
253
- toast.error(errorMessage);
254
- } finally {
255
- setIsSubmitting(false);
256
- }
257
- };
258
- const isLoading = isSubmitting || isChecking;
259
- return /* @__PURE__ */ jsxs(
260
- "form",
261
- {
262
- onSubmit: handleSubmit(onEmailPasswordSubmit),
263
- className: "p-4 space-y-4 border-t",
264
- children: [
265
- /* @__PURE__ */ jsxs("div", { className: "space-y-4 w-full md:w-1/2", children: [
266
- /* @__PURE__ */ jsxs("div", { className: "space-y-2", children: [
267
- /* @__PURE__ */ jsx2(Label, { htmlFor: "email", children: "New Email Address" }),
268
- /* @__PURE__ */ jsx2(
269
- Input,
270
- {
271
- id: "email",
272
- type: "email",
273
- placeholder: "Enter your new email",
274
- ...register("email"),
275
- disabled: isLoading
276
- }
277
- ),
278
- errors.email && /* @__PURE__ */ jsx2("p", { className: "text-sm text-destructive", children: errors.email.message })
279
- ] }),
280
- /* @__PURE__ */ jsxs("div", { className: "space-y-2", children: [
281
- /* @__PURE__ */ jsx2(Label, { htmlFor: "password", children: "Password" }),
282
- /* @__PURE__ */ jsxs("div", { className: "relative", children: [
283
- /* @__PURE__ */ jsx2(
284
- Input,
285
- {
286
- id: "password",
287
- type: showPassword ? "text" : "password",
288
- autoComplete: "current-password",
289
- placeholder: "Enter your password",
290
- ...register("password"),
291
- disabled: isLoading
292
- }
293
- ),
294
- /* @__PURE__ */ jsx2(
295
- "button",
296
- {
297
- type: "button",
298
- onClick: () => setShowPassword(!showPassword),
299
- className: "absolute right-3 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground",
300
- disabled: isLoading,
301
- children: showPassword ? /* @__PURE__ */ jsx2(IconEyeOff, { className: "h-4 w-4" }) : /* @__PURE__ */ jsx2(IconEye, { className: "h-4 w-4" })
302
- }
303
- )
304
- ] }),
305
- errors.password && /* @__PURE__ */ jsx2("p", { className: "text-sm text-destructive", children: errors.password.message })
306
- ] })
307
- ] }),
308
- /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
309
- /* @__PURE__ */ jsx2(
310
- Button,
311
- {
312
- type: "button",
313
- variant: "outline",
314
- onClick: onCancel,
315
- disabled: isLoading,
316
- children: "Cancel"
317
- }
318
- ),
319
- /* @__PURE__ */ jsxs(Button, { type: "submit", disabled: isLoading, children: [
320
- isLoading && /* @__PURE__ */ jsx2(Spinner, { className: "mr-2 h-4 w-4" }),
321
- isChecking ? "Checking\u2026" : buttonText
322
- ] })
323
- ] })
324
- ]
325
- }
326
- );
327
- }
328
-
329
- // src/components/profile/verify-change-email-form.tsx
330
- import { useState as useState4 } from "react";
331
- import { toast as toast2 } from "sonner";
332
-
333
- // src/components/profile/otp-verification-modal.tsx
334
- import {
335
- Dialog,
336
- DialogContent,
337
- DialogDescription,
338
- DialogHeader,
339
- DialogTitle
340
- } from "@mesob/ui/components";
341
-
342
- // src/components/auth/verification-form.tsx
343
- import { zodResolver as zodResolver2 } from "@hookform/resolvers/zod";
344
- import {
345
- Button as Button2,
346
- Form,
347
- FormControl,
348
- FormField,
349
- FormItem,
350
- FormLabel,
351
- FormMessage,
352
- InputOTP,
353
- InputOTPGroup,
354
- InputOTPSlot
355
- } from "@mesob/ui/components";
356
- import { useForm as useForm2 } from "react-hook-form";
357
- import { z as z2 } from "zod";
358
-
359
- // src/hooks/use-translator.ts
360
- import { useMesob } from "@mesob/ui/providers";
361
- function useTranslator(namespace) {
362
- const mesob = useMesob();
363
- const { config } = useConfig();
364
- if (mesob?.t) {
365
- return (key, params) => {
366
- const fullKey = namespace ? `${namespace}.${key}` : key;
367
- return mesob.t?.(fullKey, params) ?? fullKey;
368
- };
369
- }
370
- return createTranslator(config.messages || {}, namespace);
371
- }
372
-
373
- // src/components/auth/countdown.tsx
374
- import { Spinner as Spinner2 } from "@mesob/ui/components";
375
- import { useEffect as useEffect2, useState as useState3 } from "react";
376
- import { jsx as jsx3, jsxs as jsxs2 } from "react/jsx-runtime";
377
- var Countdown = ({
378
- initialSeconds = 60,
379
- onResend,
380
- resending = false
381
- }) => {
382
- const t = useTranslator("Common");
383
- const [seconds, setSeconds] = useState3(initialSeconds);
384
- const [isResending, setIsResending] = useState3(false);
385
- useEffect2(() => {
386
- if (seconds <= 0) {
387
- return;
388
- }
389
- const timer = setInterval(() => {
390
- setSeconds((prev) => {
391
- if (prev <= 1) {
392
- clearInterval(timer);
393
- return 0;
394
- }
395
- return prev - 1;
396
- });
397
- }, 1e3);
398
- return () => clearInterval(timer);
399
- }, [seconds]);
400
- const handleResend = async () => {
401
- setIsResending(true);
402
- try {
403
- await onResend();
404
- setSeconds(initialSeconds);
405
- } catch (_error) {
406
- } finally {
407
- setIsResending(false);
408
- }
409
- };
410
- const busy = isResending || resending;
411
- if (seconds > 0) {
412
- return /* @__PURE__ */ jsx3("p", { className: "text-sm text-muted-foreground", children: t("resendIn", { seconds }) });
413
- }
414
- return /* @__PURE__ */ jsxs2(
415
- "button",
416
- {
417
- type: "button",
418
- onClick: handleResend,
419
- disabled: busy,
420
- className: "text-sm text-primary hover:underline disabled:opacity-50 flex items-center gap-1",
421
- children: [
422
- busy && /* @__PURE__ */ jsx3(Spinner2, { className: "h-3 w-3" }),
423
- t("resend")
424
- ]
425
- }
426
- );
427
- };
428
-
429
- // src/components/auth/verification-form.tsx
430
- import { jsx as jsx4, jsxs as jsxs3 } from "react/jsx-runtime";
431
- var verificationSchema = (t) => z2.object({
432
- code: z2.string().length(6, t("form.codeLength"))
433
- });
434
- var VerificationForm = ({
435
- onSubmit,
436
- onResend,
437
- isLoading = false
438
- }) => {
439
- const t = useTranslator("Auth.verification");
440
- const form = useForm2({
441
- resolver: zodResolver2(verificationSchema(t)),
442
- defaultValues: { code: "" }
443
- });
444
- const handleSubmit = form.handleSubmit(async (values) => {
445
- await onSubmit(values);
446
- });
447
- const codeLength = form.watch("code").length;
448
- return /* @__PURE__ */ jsx4(Form, { ...form, children: /* @__PURE__ */ jsxs3(
449
- "form",
450
- {
451
- id: "verification-form",
452
- onSubmit: handleSubmit,
453
- className: "space-y-4",
454
- children: [
455
- /* @__PURE__ */ jsx4(
456
- FormField,
457
- {
458
- control: form.control,
459
- name: "code",
460
- render: ({ field }) => /* @__PURE__ */ jsxs3(FormItem, { children: [
461
- /* @__PURE__ */ jsx4("div", { className: "flex justify-center", children: /* @__PURE__ */ jsx4(FormLabel, { children: t("form.codeLabel") }) }),
462
- /* @__PURE__ */ jsx4(FormControl, { children: /* @__PURE__ */ jsx4(
463
- InputOTP,
464
- {
465
- maxLength: 6,
466
- required: true,
467
- value: field.value ?? "",
468
- onChange: field.onChange,
469
- onBlur: field.onBlur,
470
- containerClassName: "gap-4 justify-center mb-2 flex items-center",
471
- children: /* @__PURE__ */ jsxs3(InputOTPGroup, { className: "gap-3 *:data-[slot=input-otp-slot]:h-12 *:data-[slot=input-otp-slot]:w-12 *:data-[slot=input-otp-slot]:rounded-md *:data-[slot=input-otp-slot]:border *:data-[slot=input-otp-slot]:text-xl", children: [
472
- /* @__PURE__ */ jsx4(InputOTPSlot, { className: "h-12", index: 0 }),
473
- /* @__PURE__ */ jsx4(InputOTPSlot, { className: "h-12", index: 1 }),
474
- /* @__PURE__ */ jsx4(InputOTPSlot, { className: "h-12", index: 2 }),
475
- /* @__PURE__ */ jsx4(InputOTPSlot, { className: "h-12", index: 3 }),
476
- /* @__PURE__ */ jsx4(InputOTPSlot, { className: "h-12", index: 4 }),
477
- /* @__PURE__ */ jsx4(InputOTPSlot, { className: "h-12", index: 5 })
478
- ] })
479
- }
480
- ) }),
481
- /* @__PURE__ */ jsx4(FormMessage, {})
482
- ] })
483
- }
484
- ),
485
- /* @__PURE__ */ jsx4(
486
- Button2,
487
- {
488
- type: "submit",
489
- form: "verification-form",
490
- className: "w-full",
491
- disabled: isLoading || codeLength !== 6,
492
- loading: isLoading,
493
- children: t("form.confirm")
494
- }
495
- ),
496
- /* @__PURE__ */ jsx4("div", { className: "flex justify-center", children: /* @__PURE__ */ jsx4(Countdown, { onResend, resending: isLoading }) })
497
- ]
498
- }
499
- ) });
500
- };
501
-
502
- // src/components/profile/otp-verification-modal.tsx
503
- import { jsx as jsx5, jsxs as jsxs4 } from "react/jsx-runtime";
504
- function OtpVerificationModal({
505
- open,
506
- title,
507
- description,
508
- verificationId,
509
- isLoading,
510
- onSubmit,
511
- onResend,
512
- onCancel
513
- }) {
514
- return /* @__PURE__ */ jsx5(
515
- Dialog,
516
- {
517
- open,
518
- onOpenChange: (nextOpen) => {
519
- if (!nextOpen) {
520
- onCancel?.();
521
- }
522
- },
523
- children: /* @__PURE__ */ jsxs4(DialogContent, { children: [
524
- /* @__PURE__ */ jsxs4(DialogHeader, { children: [
525
- /* @__PURE__ */ jsx5(DialogTitle, { children: title }),
526
- description && /* @__PURE__ */ jsx5(DialogDescription, { children: description })
527
- ] }),
528
- /* @__PURE__ */ jsx5(
529
- VerificationForm,
530
- {
531
- verificationId,
532
- isLoading,
533
- onSubmit: async ({ code }) => onSubmit(code),
534
- onResend: onResend ?? (() => void 0)
535
- }
536
- )
537
- ] })
538
- }
539
- );
540
- }
541
-
542
- // src/components/profile/verify-change-email-form.tsx
543
- import { jsx as jsx6 } from "react/jsx-runtime";
544
- function isAuthError2(error) {
545
- return typeof error === "object" && error !== null && ("code" in error || "message" in error || "name" in error);
546
- }
547
- function getErrorCode2(error) {
548
- if (error.code) {
549
- return error.code;
550
- }
551
- if (error.message) {
552
- const upperMessage = error.message.toUpperCase().trim();
553
- const validCodes = [
554
- "USER_NOT_FOUND",
555
- "USER_EXISTS",
556
- "INVALID_PASSWORD",
557
- "VERIFICATION_EXPIRED",
558
- "VERIFICATION_MISMATCH",
559
- "VERIFICATION_NOT_FOUND",
560
- "TOO_MANY_ATTEMPTS",
561
- "UNAUTHORIZED"
562
- ];
563
- if (validCodes.includes(upperMessage)) {
564
- return upperMessage;
565
- }
566
- }
567
- return void 0;
568
- }
569
- function getErrorMessage2(error) {
570
- if (isAuthError2(error)) {
571
- const errorCode = getErrorCode2(error);
572
- switch (errorCode) {
573
- case "USER_EXISTS":
574
- return "This email is already taken. Please use a different email.";
575
- case "VERIFICATION_EXPIRED":
576
- return "Verification code has expired. Please request a new one.";
577
- case "VERIFICATION_MISMATCH":
578
- return "Invalid verification code. Please try again.";
579
- case "VERIFICATION_NOT_FOUND":
580
- return "Verification not found. Please request a new code.";
581
- default:
582
- return error.message || "An error occurred. Please try again.";
583
- }
584
- }
585
- if (error instanceof Error) {
586
- return error.message;
587
- }
588
- return "An error occurred. Please try again.";
589
- }
590
- function VerifyChangeEmailForm({
591
- email,
592
- verificationId,
593
- onSuccess,
594
- onCancel
595
- }) {
596
- const { refresh } = useSession();
597
- const { hooks } = useApi();
598
- const [isSubmitting, setIsSubmitting] = useState4(false);
599
- const [currentVerificationId, setCurrentVerificationId] = useState4(verificationId);
600
- const verifyEmailMutation = hooks.useMutation(
601
- "post",
602
- "/email/verification/confirm"
603
- );
604
- const updateEmailMutation = hooks.useMutation("put", "/profile/email");
605
- const requestEmailVerificationMutation = hooks.useMutation(
606
- "post",
607
- "/email/verification/request"
608
- );
609
- const onOtpSubmit = async (code) => {
610
- if (!currentVerificationId) {
611
- toast2.error("Verification not found. Please request a new code.");
612
- return;
613
- }
614
- try {
615
- setIsSubmitting(true);
616
- await verifyEmailMutation.mutateAsync({
617
- body: {
618
- verificationId: currentVerificationId,
619
- code
620
- }
621
- });
622
- await updateEmailMutation.mutateAsync({
623
- body: { email }
624
- });
625
- toast2.success("Email updated successfully");
626
- await refresh();
627
- onSuccess();
628
- } catch (error) {
629
- const errorMessage = getErrorMessage2(error);
630
- toast2.error(errorMessage);
631
- } finally {
632
- setIsSubmitting(false);
633
- }
634
- };
635
- if (!currentVerificationId) {
636
- toast2.error("Verification not found. Please request a new code.");
637
- return null;
638
- }
639
- return /* @__PURE__ */ jsx6(
640
- OtpVerificationModal,
641
- {
642
- open: true,
643
- title: "Verify email",
644
- description: `Enter the verification code sent to ${email}`,
645
- verificationId: currentVerificationId,
646
- isLoading: isSubmitting,
647
- onSubmit: onOtpSubmit,
648
- onResend: async () => {
649
- try {
650
- setIsSubmitting(true);
651
- const next = await requestEmailVerificationMutation.mutateAsync({
652
- body: { email }
653
- });
654
- setCurrentVerificationId(next.data?.verificationId ?? null);
655
- toast2.success("Verification code resent");
656
- } catch (error) {
657
- toast2.error(getErrorMessage2(error));
658
- } finally {
659
- setIsSubmitting(false);
660
- }
661
- },
662
- onCancel
663
- }
664
- );
665
- }
666
-
667
- // src/components/profile/change-email-form.tsx
668
- import { jsx as jsx7, jsxs as jsxs5 } from "react/jsx-runtime";
669
- function ChangeEmailForm() {
670
- const { user } = useSession();
671
- const [isOpen, setIsOpen] = useState5(false);
672
- const [showOtp, setShowOtp] = useState5(false);
673
- const [verificationId, setVerificationId] = useState5(null);
674
- const [newEmail, setNewEmail] = useState5("");
675
- const resetForms = () => {
676
- setShowOtp(false);
677
- setVerificationId(null);
678
- setNewEmail("");
679
- };
680
- const handleRequestSuccess = (id, email) => {
681
- setVerificationId(id);
682
- setNewEmail(email);
683
- setShowOtp(true);
684
- };
685
- const handleVerifySuccess = () => {
686
- resetForms();
687
- setIsOpen(false);
688
- };
689
- const handleCancel = () => {
690
- resetForms();
691
- setIsOpen(false);
692
- };
693
- const title = user?.email ? "Change Email" : "Add Email";
694
- const description = user?.email ? "Update your email address" : "Add an email address to your account";
695
- return /* @__PURE__ */ jsx7(Collapsible, { open: isOpen, onOpenChange: setIsOpen, children: /* @__PURE__ */ jsxs5("div", { className: "border rounded-lg", children: [
696
- /* @__PURE__ */ jsxs5(
697
- CollapsibleTrigger,
698
- {
699
- render: /* @__PURE__ */ jsx7(
700
- Button3,
701
- {
702
- variant: "ghost",
703
- className: "w-full justify-between p-4 h-auto"
704
- }
705
- ),
706
- children: [
707
- /* @__PURE__ */ jsxs5("div", { className: "flex flex-col items-start", children: [
708
- /* @__PURE__ */ jsx7("span", { className: "font-medium", children: title }),
709
- /* @__PURE__ */ jsx7("span", { className: "text-sm text-muted-foreground", children: description })
710
- ] }),
711
- /* @__PURE__ */ jsx7(
712
- IconChevronDown,
713
- {
714
- className: `h-4 w-4 transition-transform ${isOpen ? "rotate-180" : ""}`
715
- }
716
- )
717
- ]
718
- }
719
- ),
720
- /* @__PURE__ */ jsx7(CollapsibleContent, { children: showOtp ? /* @__PURE__ */ jsx7(
721
- VerifyChangeEmailForm,
722
- {
723
- email: newEmail,
724
- verificationId,
725
- onSuccess: handleVerifySuccess,
726
- onCancel: handleCancel
727
- }
728
- ) : /* @__PURE__ */ jsx7(
729
- RequestChangeEmailForm,
730
- {
731
- onSuccess: handleRequestSuccess,
732
- onCancel: handleCancel,
733
- buttonText: title
734
- }
735
- ) })
736
- ] }) });
737
- }
738
-
739
- // src/components/profile/change-password-form.tsx
740
- import { zodResolver as zodResolver3 } from "@hookform/resolvers/zod";
741
- import {
742
- Button as Button4,
743
- Collapsible as Collapsible2,
744
- CollapsibleContent as CollapsibleContent2,
745
- CollapsibleTrigger as CollapsibleTrigger2,
746
- Input as Input2,
747
- Label as Label2,
748
- Spinner as Spinner3
749
- } from "@mesob/ui/components";
750
- import { IconChevronDown as IconChevronDown2, IconEye as IconEye2, IconEyeOff as IconEyeOff2 } from "@tabler/icons-react";
751
- import { useState as useState6 } from "react";
752
- import { useForm as useForm3 } from "react-hook-form";
753
- import { toast as toast3 } from "sonner";
754
- import { z as z3 } from "zod";
755
- import { jsx as jsx8, jsxs as jsxs6 } from "react/jsx-runtime";
756
- var changePasswordSchema = z3.object({
757
- currentPassword: z3.string().min(8, "Password must be at least 8 characters"),
758
- newPassword: z3.string().min(8, "Password must be at least 8 characters"),
759
- confirmPassword: z3.string().min(8, "Password must be at least 8 characters")
760
- }).refine((data) => data.newPassword === data.confirmPassword, {
761
- message: "Passwords don't match",
762
- path: ["confirmPassword"]
763
- });
764
- function isAuthError3(error) {
765
- return typeof error === "object" && error !== null && ("code" in error || "message" in error || "name" in error);
766
- }
767
- function getErrorCode3(error) {
768
- if (error.code) {
769
- return error.code;
770
- }
771
- if (error.message) {
772
- const upperMessage = error.message.toUpperCase().trim();
773
- const validCodes = [
774
- "INVALID_PASSWORD",
775
- "UNAUTHORIZED",
776
- "HAS_NO_PASSWORD",
777
- "USER_NOT_FOUND",
778
- "USER_EXISTS",
779
- "VERIFICATION_EXPIRED",
780
- "VERIFICATION_MISMATCH",
781
- "VERIFICATION_NOT_FOUND",
782
- "TOO_MANY_ATTEMPTS",
783
- "REQUIRES_VERIFICATION",
784
- "ACCESS_DENIED"
785
- ];
786
- if (validCodes.includes(upperMessage)) {
787
- return upperMessage;
788
- }
789
- }
790
- return void 0;
791
- }
792
- function getPasswordChangeErrorMessage(error) {
793
- if (isAuthError3(error)) {
794
- const errorCode = getErrorCode3(error);
795
- switch (errorCode) {
796
- case "INVALID_PASSWORD":
797
- return "The current password you entered is incorrect. Please try again.";
798
- case "UNAUTHORIZED":
799
- return "You are not authorized to perform this action. Please sign in again.";
800
- case "HAS_NO_PASSWORD":
801
- return "Your account does not have a password set. Please use password reset instead.";
802
- default:
803
- return error.message || "Failed to change password. Please try again.";
804
- }
805
- }
806
- if (error instanceof Error) {
807
- return error.message;
808
- }
809
- return "Failed to change password. Please try again.";
810
- }
811
- function ChangePasswordForm() {
812
- const { user: _user } = useSession();
813
- const [isOpen, setIsOpen] = useState6(false);
814
- const [isSubmitting, setIsSubmitting] = useState6(false);
815
- const [showPassword, setShowPassword] = useState6(false);
816
- const [showNewPassword, setShowNewPassword] = useState6(false);
817
- const [showConfirmPassword, setShowConfirmPassword] = useState6(false);
818
- const form = useForm3({
819
- resolver: zodResolver3(changePasswordSchema),
820
- defaultValues: {
821
- currentPassword: "",
822
- newPassword: "",
823
- confirmPassword: ""
824
- }
825
- });
826
- const { register, handleSubmit, formState, reset } = form;
827
- const onSubmit = (_data) => {
828
- try {
829
- setIsSubmitting(true);
830
- toast3.error("Password change unavailable");
831
- setIsOpen(false);
832
- } catch (error) {
833
- const errorMessage = getPasswordChangeErrorMessage(error);
834
- toast3.error(errorMessage);
835
- } finally {
836
- setIsSubmitting(false);
837
- }
838
- };
839
- return /* @__PURE__ */ jsx8(Collapsible2, { open: isOpen, onOpenChange: setIsOpen, children: /* @__PURE__ */ jsxs6("div", { className: "border rounded-lg", children: [
840
- /* @__PURE__ */ jsxs6(
841
- CollapsibleTrigger2,
842
- {
843
- render: /* @__PURE__ */ jsx8(
844
- Button4,
845
- {
846
- variant: "ghost",
847
- className: "w-full justify-between p-4 h-auto"
848
- }
849
- ),
850
- children: [
851
- /* @__PURE__ */ jsxs6("div", { className: "flex flex-col items-start", children: [
852
- /* @__PURE__ */ jsx8("span", { className: "font-medium", children: "Change Password" }),
853
- /* @__PURE__ */ jsx8("span", { className: "text-sm text-muted-foreground", children: "Update your account password" })
854
- ] }),
855
- /* @__PURE__ */ jsx8(
856
- IconChevronDown2,
857
- {
858
- className: `h-4 w-4 transition-transform ${isOpen ? "rotate-180" : ""}`
859
- }
860
- )
861
- ]
862
- }
863
- ),
864
- /* @__PURE__ */ jsx8(CollapsibleContent2, { children: /* @__PURE__ */ jsxs6(
865
- "form",
866
- {
867
- onSubmit: handleSubmit(onSubmit),
868
- className: "p-4 space-y-4 border-t",
869
- children: [
870
- /* @__PURE__ */ jsxs6("div", { className: "space-y-2 w-full md:w-1/2", children: [
871
- /* @__PURE__ */ jsx8(Label2, { htmlFor: "currentPassword", children: "Old Password" }),
872
- /* @__PURE__ */ jsxs6("div", { className: "relative", children: [
873
- /* @__PURE__ */ jsx8(
874
- Input2,
875
- {
876
- id: "currentPassword",
877
- type: showPassword ? "text" : "password",
878
- autoComplete: "current-password",
879
- placeholder: "Enter your current password",
880
- ...register("currentPassword")
881
- }
882
- ),
883
- /* @__PURE__ */ jsx8(
884
- "button",
885
- {
886
- type: "button",
887
- onClick: () => setShowPassword(!showPassword),
888
- className: "absolute right-3 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground",
889
- children: showPassword ? /* @__PURE__ */ jsx8(IconEyeOff2, { className: "h-4 w-4" }) : /* @__PURE__ */ jsx8(IconEye2, { className: "h-4 w-4" })
890
- }
891
- )
892
- ] }),
893
- formState.errors.currentPassword && /* @__PURE__ */ jsx8("p", { className: "text-sm text-destructive", children: formState.errors.currentPassword.message })
894
- ] }),
895
- /* @__PURE__ */ jsxs6("div", { className: "space-y-2 w-full md:w-1/2", children: [
896
- /* @__PURE__ */ jsx8(Label2, { htmlFor: "newPassword", children: "New Password" }),
897
- /* @__PURE__ */ jsxs6("div", { className: "relative", children: [
898
- /* @__PURE__ */ jsx8(
899
- Input2,
900
- {
901
- id: "newPassword",
902
- type: showNewPassword ? "text" : "password",
903
- placeholder: "Enter your new password",
904
- autoComplete: "new-password",
905
- ...register("newPassword")
906
- }
907
- ),
908
- /* @__PURE__ */ jsx8(
909
- "button",
910
- {
911
- type: "button",
912
- onClick: () => setShowNewPassword(!showNewPassword),
913
- className: "absolute right-3 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground",
914
- children: showNewPassword ? /* @__PURE__ */ jsx8(IconEyeOff2, { className: "h-4 w-4" }) : /* @__PURE__ */ jsx8(IconEye2, { className: "h-4 w-4" })
915
- }
916
- )
917
- ] }),
918
- formState.errors.newPassword && /* @__PURE__ */ jsx8("p", { className: "text-sm text-destructive", children: formState.errors.newPassword.message })
919
- ] }),
920
- /* @__PURE__ */ jsxs6("div", { className: "space-y-2 w-full md:w-1/2", children: [
921
- /* @__PURE__ */ jsx8(Label2, { htmlFor: "confirmPassword", children: "Confirm New Password" }),
922
- /* @__PURE__ */ jsxs6("div", { className: "relative", children: [
923
- /* @__PURE__ */ jsx8(
924
- Input2,
925
- {
926
- id: "confirmPassword",
927
- type: showConfirmPassword ? "text" : "password",
928
- placeholder: "Confirm your new password",
929
- autoComplete: "new-password",
930
- ...register("confirmPassword")
931
- }
932
- ),
933
- /* @__PURE__ */ jsx8(
934
- "button",
935
- {
936
- type: "button",
937
- onClick: () => setShowConfirmPassword(!showConfirmPassword),
938
- className: "absolute right-3 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground",
939
- children: showConfirmPassword ? /* @__PURE__ */ jsx8(IconEyeOff2, { className: "h-4 w-4" }) : /* @__PURE__ */ jsx8(IconEye2, { className: "h-4 w-4" })
940
- }
941
- )
942
- ] }),
943
- formState.errors.confirmPassword && /* @__PURE__ */ jsx8("p", { className: "text-sm text-destructive", children: formState.errors.confirmPassword.message })
944
- ] }),
945
- /* @__PURE__ */ jsxs6("div", { className: "flex justify-end gap-2", children: [
946
- /* @__PURE__ */ jsx8(
947
- Button4,
948
- {
949
- type: "button",
950
- variant: "outline",
951
- onClick: () => {
952
- reset();
953
- setIsOpen(false);
954
- },
955
- disabled: isSubmitting,
956
- children: "Cancel"
957
- }
958
- ),
959
- /* @__PURE__ */ jsxs6(Button4, { type: "submit", disabled: isSubmitting, children: [
960
- isSubmitting && /* @__PURE__ */ jsx8(Spinner3, { className: "mr-2 h-4 w-4" }),
961
- "Change Password"
962
- ] })
963
- ] })
964
- ]
965
- }
966
- ) })
967
- ] }) });
968
- }
969
-
970
- // src/components/profile/change-phone-form.tsx
971
- import {
972
- Button as Button6,
973
- Collapsible as Collapsible3,
974
- CollapsibleContent as CollapsibleContent3,
975
- CollapsibleTrigger as CollapsibleTrigger3
976
- } from "@mesob/ui/components";
977
- import { IconChevronDown as IconChevronDown3 } from "@tabler/icons-react";
978
- import { useState as useState9 } from "react";
979
-
980
- // src/components/profile/request-change-phone-form.tsx
981
- import { zodResolver as zodResolver4 } from "@hookform/resolvers/zod";
982
- import { Button as Button5, Input as Input3, Label as Label3, Spinner as Spinner4 } from "@mesob/ui/components";
983
- import { IconEye as IconEye3, IconEyeOff as IconEyeOff3 } from "@tabler/icons-react";
984
- import { useEffect as useEffect3, useState as useState7 } from "react";
985
- import { useForm as useForm4 } from "react-hook-form";
986
- import { toast as toast4 } from "sonner";
987
- import { z as z4 } from "zod";
988
-
989
- // src/utils/normalize-phone.ts
990
- function normalizePhone(phone) {
991
- const cleaned = phone.trim().replace(/\s/g, "");
992
- if (cleaned.startsWith("+2519") || cleaned.startsWith("+2517")) {
993
- return cleaned;
994
- }
995
- if (cleaned.startsWith("2519") || cleaned.startsWith("2517")) {
996
- return `+${cleaned}`;
997
- }
998
- if (cleaned.startsWith("09") || cleaned.startsWith("07")) {
999
- return `+251${cleaned.slice(1)}`;
1000
- }
1001
- if ((cleaned.startsWith("9") || cleaned.startsWith("7")) && cleaned.length === 9) {
1002
- return `+251${cleaned}`;
1003
- }
1004
- return cleaned;
1005
- }
1006
-
1007
- // src/components/profile/request-change-phone-form.tsx
1008
- import { jsx as jsx9, jsxs as jsxs7 } from "react/jsx-runtime";
1009
- var phonePasswordSchema = (phoneRegex) => z4.object({
1010
- phone: z4.string().trim().min(1, { message: "Phone number is required" }).refine(
1011
- (val) => {
1012
- const isPhone = phoneRegex.test(val);
1013
- return isPhone;
1014
- },
1015
- {
1016
- message: "Invalid phone number"
1017
- }
1018
- ),
1019
- password: z4.string().min(8, "Password must be at least 8 characters").max(128, "Password too long")
1020
- });
1021
- function isAuthError4(error) {
1022
- return typeof error === "object" && error !== null && ("code" in error || "message" in error || "name" in error);
1023
- }
1024
- function getErrorCode4(error) {
1025
- if (error.code) {
1026
- return error.code;
1027
- }
1028
- if (error.message) {
1029
- const upperMessage = error.message.toUpperCase().trim();
1030
- const validCodes = [
1031
- "USER_NOT_FOUND",
1032
- "USER_EXISTS",
1033
- "INVALID_PASSWORD",
1034
- "VERIFICATION_EXPIRED",
1035
- "VERIFICATION_MISMATCH",
1036
- "VERIFICATION_NOT_FOUND",
1037
- "TOO_MANY_ATTEMPTS",
1038
- "UNAUTHORIZED"
1039
- ];
1040
- if (validCodes.includes(upperMessage)) {
1041
- return upperMessage;
1042
- }
1043
- }
1044
- return void 0;
1045
- }
1046
- function getErrorMessage3(error) {
1047
- if (isAuthError4(error)) {
1048
- const errorCode = getErrorCode4(error);
1049
- switch (errorCode) {
1050
- case "USER_EXISTS":
1051
- return "This phone number is already taken. Please use a different number.";
1052
- case "VERIFICATION_EXPIRED":
1053
- return "Verification code has expired. Please request a new one.";
1054
- case "VERIFICATION_MISMATCH":
1055
- return "Invalid verification code. Please try again.";
1056
- case "VERIFICATION_NOT_FOUND":
1057
- return "Verification not found. Please request a new code.";
1058
- default:
1059
- return error.message || "An error occurred. Please try again.";
1060
- }
1061
- }
1062
- if (error instanceof Error) {
1063
- return error.message;
1064
- }
1065
- return "An error occurred. Please try again.";
1066
- }
1067
- function RequestChangePhoneForm({
1068
- onSuccess,
1069
- onCancel,
1070
- buttonText
1071
- }) {
1072
- const { user } = useSession();
1073
- const { hooks } = useApi();
1074
- const { config } = useConfig();
1075
- const [isSubmitting, setIsSubmitting] = useState7(false);
1076
- const [isChecking, setIsChecking] = useState7(true);
1077
- const [showPassword, setShowPassword] = useState7(false);
1078
- const phoneRegex = typeof config.phoneRegex === "string" ? new RegExp(config.phoneRegex) : config.phoneRegex || /^(\+2519|\+2517|2519|2517|09|07)\d{8}$/;
1079
- const getPendingAccountChangeQuery = hooks.useQuery(
1080
- "get",
1081
- "/account-change/pending",
1082
- {},
1083
- { enabled: false }
1084
- );
1085
- const verifyPasswordMutation = hooks.useMutation("post", "/password/verify");
1086
- const checkUserMutation = hooks.useMutation("post", "/check-account");
1087
- const requestPhoneOtpMutation = hooks.useMutation(
1088
- "post",
1089
- "/phone/verification/request"
1090
- );
1091
- const phonePasswordForm = useForm4({
1092
- resolver: zodResolver4(phonePasswordSchema(phoneRegex)),
1093
- defaultValues: {
1094
- phone: "",
1095
- password: ""
1096
- }
1097
- });
1098
- const {
1099
- register,
1100
- handleSubmit,
1101
- getValues,
1102
- setValue,
1103
- formState: { errors }
1104
- } = phonePasswordForm;
1105
- useEffect3(() => {
1106
- let active = true;
1107
- const run = async () => {
1108
- try {
1109
- const data = await getPendingAccountChangeQuery.refetch();
1110
- if (!active) {
1111
- return;
1112
- }
1113
- const accountChange = data.data?.accountChange;
1114
- const verificationId = data.data?.verificationId;
1115
- if (accountChange?.changeType !== "phone") {
1116
- setIsChecking(false);
1117
- return;
1118
- }
1119
- if (!accountChange.newPhone) {
1120
- setIsChecking(false);
1121
- return;
1122
- }
1123
- if (getValues("phone")) {
1124
- setIsChecking(false);
1125
- return;
1126
- }
1127
- setValue("phone", accountChange.newPhone, { shouldValidate: true });
1128
- if (verificationId) {
1129
- toast4.message("Resuming verification\u2026");
1130
- onSuccess(verificationId, accountChange.newPhone);
1131
- return;
1132
- }
1133
- setIsChecking(false);
1134
- } catch {
1135
- setIsChecking(false);
1136
- }
1137
- };
1138
- run().catch(() => void 0);
1139
- return () => {
1140
- active = false;
1141
- };
1142
- }, [getPendingAccountChangeQuery.refetch, getValues, onSuccess, setValue]);
1143
- const onPhonePasswordSubmit = async (data) => {
1144
- if (!user) {
1145
- toast4.error("User not found");
1146
- return;
1147
- }
1148
- try {
1149
- setIsSubmitting(true);
1150
- const normalizedPhone = normalizePhone(data.phone);
1151
- await verifyPasswordMutation.mutateAsync({
1152
- body: { password: data.password }
1153
- });
1154
- const checkResult = await checkUserMutation.mutateAsync({
1155
- body: { identifier: normalizedPhone }
1156
- });
1157
- if (checkResult.data?.exists) {
1158
- if (user?.phone?.replace(/\s/g, "") === normalizedPhone.replace(/\s/g, "")) {
1159
- toast4.error("This is already your current phone number.");
1160
- return;
1161
- }
1162
- toast4.error(
1163
- "This phone number is already taken. Please use a different number."
1164
- );
1165
- return;
1166
- }
1167
- const verification = await requestPhoneOtpMutation.mutateAsync({
1168
- body: {
1169
- phone: normalizedPhone,
1170
- context: "change-phone"
1171
- }
1172
- });
1173
- toast4.success("Verification code sent to your phone");
1174
- onSuccess(verification.data?.verificationId ?? "", normalizedPhone);
1175
- } catch (error) {
1176
- const errorMessage = getErrorMessage3(error);
1177
- if (isAuthError4(error)) {
1178
- const errorCode = getErrorCode4(error);
1179
- if (errorCode === "INVALID_PASSWORD" || errorCode === "USER_NOT_FOUND") {
1180
- toast4.error("Incorrect password. Please try again.");
1181
- return;
1182
- }
1183
- }
1184
- toast4.error(errorMessage);
1185
- } finally {
1186
- setIsSubmitting(false);
1187
- }
1188
- };
1189
- const isLoading = isSubmitting || isChecking;
1190
- return /* @__PURE__ */ jsxs7(
1191
- "form",
1192
- {
1193
- onSubmit: handleSubmit(onPhonePasswordSubmit),
1194
- className: "p-4 space-y-4 border-t",
1195
- children: [
1196
- /* @__PURE__ */ jsxs7("div", { className: "space-y-4 w-full md:w-1/2", children: [
1197
- /* @__PURE__ */ jsxs7("div", { className: "space-y-2", children: [
1198
- /* @__PURE__ */ jsx9(Label3, { htmlFor: "phone", children: "Phone Number" }),
1199
- /* @__PURE__ */ jsx9(
1200
- Input3,
1201
- {
1202
- id: "phone",
1203
- type: "tel",
1204
- placeholder: "Enter your new phone number",
1205
- ...register("phone"),
1206
- disabled: isLoading
1207
- }
1208
- ),
1209
- errors.phone && /* @__PURE__ */ jsx9("p", { className: "text-sm text-destructive", children: errors.phone.message })
1210
- ] }),
1211
- /* @__PURE__ */ jsxs7("div", { className: "space-y-2", children: [
1212
- /* @__PURE__ */ jsx9(Label3, { htmlFor: "password", children: "Password" }),
1213
- /* @__PURE__ */ jsxs7("div", { className: "relative", children: [
1214
- /* @__PURE__ */ jsx9(
1215
- Input3,
1216
- {
1217
- id: "password",
1218
- type: showPassword ? "text" : "password",
1219
- autoComplete: "current-password",
1220
- placeholder: "Enter your password",
1221
- ...register("password"),
1222
- disabled: isLoading
1223
- }
1224
- ),
1225
- /* @__PURE__ */ jsx9(
1226
- "button",
1227
- {
1228
- type: "button",
1229
- onClick: () => setShowPassword(!showPassword),
1230
- className: "absolute right-3 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground",
1231
- children: showPassword ? /* @__PURE__ */ jsx9(IconEyeOff3, { className: "h-4 w-4" }) : /* @__PURE__ */ jsx9(IconEye3, { className: "h-4 w-4" })
1232
- }
1233
- )
1234
- ] }),
1235
- errors.password && /* @__PURE__ */ jsx9("p", { className: "text-sm text-destructive", children: errors.password.message })
1236
- ] })
1237
- ] }),
1238
- /* @__PURE__ */ jsxs7("div", { className: "flex justify-end gap-2", children: [
1239
- /* @__PURE__ */ jsx9(
1240
- Button5,
1241
- {
1242
- type: "button",
1243
- variant: "outline",
1244
- onClick: onCancel,
1245
- disabled: isLoading,
1246
- children: "Cancel"
1247
- }
1248
- ),
1249
- /* @__PURE__ */ jsxs7(Button5, { type: "submit", disabled: isLoading, children: [
1250
- isLoading && /* @__PURE__ */ jsx9(Spinner4, { className: "mr-2 h-4 w-4" }),
1251
- isChecking ? "Checking\u2026" : buttonText
1252
- ] })
1253
- ] })
1254
- ]
1255
- }
1256
- );
1257
- }
1258
-
1259
- // src/components/profile/verify-change-phone-form.tsx
1260
- import { useState as useState8 } from "react";
1261
- import { toast as toast5 } from "sonner";
1262
- import { jsx as jsx10 } from "react/jsx-runtime";
1263
- function isAuthError5(error) {
1264
- return typeof error === "object" && error !== null && ("code" in error || "message" in error || "name" in error);
1265
- }
1266
- function getErrorCode5(error) {
1267
- if (error.code) {
1268
- return error.code;
1269
- }
1270
- if (error.message) {
1271
- const upperMessage = error.message.toUpperCase().trim();
1272
- const validCodes = [
1273
- "USER_NOT_FOUND",
1274
- "USER_EXISTS",
1275
- "INVALID_PASSWORD",
1276
- "VERIFICATION_EXPIRED",
1277
- "VERIFICATION_MISMATCH",
1278
- "VERIFICATION_NOT_FOUND",
1279
- "TOO_MANY_ATTEMPTS",
1280
- "UNAUTHORIZED"
1281
- ];
1282
- if (validCodes.includes(upperMessage)) {
1283
- return upperMessage;
1284
- }
1285
- }
1286
- return void 0;
1287
- }
1288
- function getErrorMessage4(error) {
1289
- if (isAuthError5(error)) {
1290
- const errorCode = getErrorCode5(error);
1291
- switch (errorCode) {
1292
- case "USER_EXISTS":
1293
- return "This phone number is already taken. Please use a different number.";
1294
- case "VERIFICATION_EXPIRED":
1295
- return "Verification code has expired. Please request a new one.";
1296
- case "VERIFICATION_MISMATCH":
1297
- return "Invalid verification code. Please try again.";
1298
- case "VERIFICATION_NOT_FOUND":
1299
- return "Verification not found. Please request a new code.";
1300
- default:
1301
- return error.message || "An error occurred. Please try again.";
1302
- }
1303
- }
1304
- if (error instanceof Error) {
1305
- return error.message;
1306
- }
1307
- return "An error occurred. Please try again.";
1308
- }
1309
- function VerifyChangePhoneForm({
1310
- phone,
1311
- verificationId,
1312
- onSuccess,
1313
- onCancel
1314
- }) {
1315
- const { refresh } = useSession();
1316
- const { hooks } = useApi();
1317
- const [isSubmitting, setIsSubmitting] = useState8(false);
1318
- const [currentVerificationId, setCurrentVerificationId] = useState8(verificationId);
1319
- const verifyPhoneOtpMutation = hooks.useMutation(
1320
- "post",
1321
- "/phone/verification/confirm"
1322
- );
1323
- const updatePhoneMutation = hooks.useMutation("put", "/profile/phone");
1324
- const requestPhoneOtpMutation = hooks.useMutation(
1325
- "post",
1326
- "/phone/verification/request"
1327
- );
1328
- const onOtpSubmit = async (code) => {
1329
- if (!currentVerificationId) {
1330
- toast5.error("Verification not found. Please request a new code.");
1331
- return;
1332
- }
1333
- try {
1334
- setIsSubmitting(true);
1335
- await verifyPhoneOtpMutation.mutateAsync({
1336
- body: {
1337
- verificationId: currentVerificationId,
1338
- code,
1339
- context: "change-phone"
1340
- }
1341
- });
1342
- await updatePhoneMutation.mutateAsync({
1343
- body: { phone }
1344
- });
1345
- toast5.success("Phone number updated successfully");
1346
- await refresh();
1347
- onSuccess();
1348
- } catch (error) {
1349
- const errorMessage = getErrorMessage4(error);
1350
- toast5.error(errorMessage);
1351
- } finally {
1352
- setIsSubmitting(false);
1353
- }
1354
- };
1355
- if (!currentVerificationId) {
1356
- toast5.error("Verification not found. Please request a new code.");
1357
- return null;
1358
- }
1359
- return /* @__PURE__ */ jsx10(
1360
- OtpVerificationModal,
1361
- {
1362
- open: true,
1363
- title: "Verify phone",
1364
- description: `Enter the verification code sent to ${phone}`,
1365
- verificationId: currentVerificationId,
1366
- isLoading: isSubmitting,
1367
- onSubmit: onOtpSubmit,
1368
- onResend: async () => {
1369
- try {
1370
- setIsSubmitting(true);
1371
- const next = await requestPhoneOtpMutation.mutateAsync({
1372
- body: {
1373
- phone,
1374
- context: "change-phone"
1375
- }
1376
- });
1377
- setCurrentVerificationId(next.data?.verificationId ?? null);
1378
- toast5.success("Verification code resent");
1379
- } catch (error) {
1380
- toast5.error(getErrorMessage4(error));
1381
- } finally {
1382
- setIsSubmitting(false);
1383
- }
1384
- },
1385
- onCancel
1386
- }
1387
- );
1388
- }
1389
-
1390
- // src/components/profile/change-phone-form.tsx
1391
- import { jsx as jsx11, jsxs as jsxs8 } from "react/jsx-runtime";
1392
- function ChangePhoneForm() {
1393
- const { user } = useSession();
1394
- const [isOpen, setIsOpen] = useState9(false);
1395
- const [showOtp, setShowOtp] = useState9(false);
1396
- const [verificationId, setVerificationId] = useState9(null);
1397
- const [newPhone, setNewPhone] = useState9("");
1398
- const resetForms = () => {
1399
- setShowOtp(false);
1400
- setVerificationId(null);
1401
- setNewPhone("");
1402
- };
1403
- const handleRequestSuccess = (id, phone) => {
1404
- setVerificationId(id);
1405
- setNewPhone(phone);
1406
- setShowOtp(true);
1407
- };
1408
- const handleVerifySuccess = () => {
1409
- resetForms();
1410
- setIsOpen(false);
1411
- };
1412
- const handleCancel = () => {
1413
- resetForms();
1414
- setIsOpen(false);
1415
- };
1416
- const title = user?.phone ? "Change Phone" : "Add Phone";
1417
- const description = user?.phone ? "Update your phone number" : "Add a phone number to your account";
1418
- return /* @__PURE__ */ jsx11(Collapsible3, { open: isOpen, onOpenChange: setIsOpen, children: /* @__PURE__ */ jsxs8("div", { className: "border rounded-lg", children: [
1419
- /* @__PURE__ */ jsxs8(
1420
- CollapsibleTrigger3,
1421
- {
1422
- render: /* @__PURE__ */ jsx11(
1423
- Button6,
1424
- {
1425
- variant: "ghost",
1426
- className: "w-full justify-between p-4 h-auto"
1427
- }
1428
- ),
1429
- children: [
1430
- /* @__PURE__ */ jsxs8("div", { className: "flex flex-col items-start", children: [
1431
- /* @__PURE__ */ jsx11("span", { className: "font-medium", children: title }),
1432
- /* @__PURE__ */ jsx11("span", { className: "text-sm text-muted-foreground", children: description })
1433
- ] }),
1434
- /* @__PURE__ */ jsx11(
1435
- IconChevronDown3,
1436
- {
1437
- className: `h-4 w-4 transition-transform ${isOpen ? "rotate-180" : ""}`
1438
- }
1439
- )
1440
- ]
1441
- }
1442
- ),
1443
- /* @__PURE__ */ jsx11(CollapsibleContent3, { children: showOtp ? /* @__PURE__ */ jsx11(
1444
- VerifyChangePhoneForm,
1445
- {
1446
- phone: newPhone,
1447
- verificationId,
1448
- onSuccess: handleVerifySuccess,
1449
- onCancel: handleCancel
1450
- }
1451
- ) : /* @__PURE__ */ jsx11(
1452
- RequestChangePhoneForm,
1453
- {
1454
- onSuccess: handleRequestSuccess,
1455
- onCancel: handleCancel,
1456
- buttonText: title
1457
- }
1458
- ) })
1459
- ] }) });
1460
- }
1461
-
1462
- // src/components/profile/security.tsx
1463
- import { jsx as jsx12, jsxs as jsxs9 } from "react/jsx-runtime";
1464
- function Security() {
1465
- return /* @__PURE__ */ jsxs9("div", { className: "p-6 space-y-6", children: [
1466
- /* @__PURE__ */ jsxs9("div", { children: [
1467
- /* @__PURE__ */ jsx12("h1", { className: "text-2xl font-semibold", children: "Security" }),
1468
- /* @__PURE__ */ jsx12("p", { className: "text-muted-foreground", children: "Manage your security settings" })
1469
- ] }),
1470
- /* @__PURE__ */ jsxs9("div", { className: "space-y-4", children: [
1471
- /* @__PURE__ */ jsx12(ChangePasswordForm, {}),
1472
- /* @__PURE__ */ jsx12(ChangeEmailForm, {}),
1473
- /* @__PURE__ */ jsx12(ChangePhoneForm, {})
1474
- ] })
1475
- ] });
1476
- }
3
+ Security
4
+ } from "../../chunk-OYHH7HQG.js";
5
+ import "../../chunk-5F5FZMHE.js";
6
+ import "../../chunk-ZG6WFZHX.js";
7
+ import "../../chunk-C26NPUPI.js";
8
+ import "../../chunk-MS2JUZ3N.js";
9
+ import "../../chunk-MELNS4QH.js";
10
+ import "../../chunk-EQ4346FE.js";
11
+ import "../../chunk-KWG4DSB5.js";
12
+ import "../../chunk-OQGJX37L.js";
13
+ import "../../chunk-FFR5UHTS.js";
14
+ import "../../chunk-GP7GIUI3.js";
15
+ import "../../chunk-V2W3WPCZ.js";
16
+ import "../../chunk-QNCE2B5O.js";
17
+ import "../../chunk-72YRO3A7.js";
1477
18
  export {
1478
19
  Security
1479
20
  };