@mesob/auth-react 0.3.4 → 0.4.0

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 (142) hide show
  1. package/dist/components/auth/auth-layout.d.ts +1 -1
  2. package/dist/components/auth/auth-layout.js +10 -2
  3. package/dist/components/auth/auth-layout.js.map +1 -1
  4. package/dist/components/auth/countdown.js +8 -6
  5. package/dist/components/auth/countdown.js.map +1 -1
  6. package/dist/components/auth/forgot-password.js +21 -19
  7. package/dist/components/auth/forgot-password.js.map +1 -1
  8. package/dist/components/auth/reset-password-form.js +22 -21
  9. package/dist/components/auth/reset-password-form.js.map +1 -1
  10. package/dist/components/auth/set-password.d.ts +9 -0
  11. package/dist/components/auth/set-password.js +527 -0
  12. package/dist/components/auth/set-password.js.map +1 -0
  13. package/dist/components/auth/sign-in.js +45 -26
  14. package/dist/components/auth/sign-in.js.map +1 -1
  15. package/dist/components/auth/sign-up.js +25 -29
  16. package/dist/components/auth/sign-up.js.map +1 -1
  17. package/dist/components/auth/verification-form.js +24 -27
  18. package/dist/components/auth/verification-form.js.map +1 -1
  19. package/dist/components/auth/verify-email.js +40 -31
  20. package/dist/components/auth/verify-email.js.map +1 -1
  21. package/dist/components/auth/verify-phone.js +40 -31
  22. package/dist/components/auth/verify-phone.js.map +1 -1
  23. package/dist/components/authorization/deny.d.ts +11 -0
  24. package/dist/components/authorization/deny.js +52 -0
  25. package/dist/components/authorization/deny.js.map +1 -0
  26. package/dist/components/authorization/grant.d.ts +12 -0
  27. package/dist/components/authorization/grant.js +57 -0
  28. package/dist/components/authorization/grant.js.map +1 -0
  29. package/dist/components/iam/permission-selector.d.ts +19 -0
  30. package/dist/components/iam/permission-selector.js +122 -0
  31. package/dist/components/iam/permission-selector.js.map +1 -0
  32. package/dist/components/iam/permissions.js +21 -33
  33. package/dist/components/iam/permissions.js.map +1 -1
  34. package/dist/components/iam/role-detail-layout.d.ts +11 -0
  35. package/dist/components/iam/role-detail-layout.js +137 -0
  36. package/dist/components/iam/role-detail-layout.js.map +1 -0
  37. package/dist/components/iam/role-detail-page.d.ts +9 -0
  38. package/dist/components/iam/role-detail-page.js +229 -0
  39. package/dist/components/iam/role-detail-page.js.map +1 -0
  40. package/dist/components/iam/role-permissions-page.d.ts +8 -0
  41. package/dist/components/iam/role-permissions-page.js +397 -0
  42. package/dist/components/iam/role-permissions-page.js.map +1 -0
  43. package/dist/components/iam/roles.js +20 -10
  44. package/dist/components/iam/roles.js.map +1 -1
  45. package/dist/components/iam/tenants.js +9 -2
  46. package/dist/components/iam/tenants.js.map +1 -1
  47. package/dist/components/iam/users.js +10 -9
  48. package/dist/components/iam/users.js.map +1 -1
  49. package/dist/components/profile/account.js +110 -19
  50. package/dist/components/profile/account.js.map +1 -1
  51. package/dist/components/profile/change-email-form.js +26 -29
  52. package/dist/components/profile/change-email-form.js.map +1 -1
  53. package/dist/components/profile/change-phone-form.js +26 -29
  54. package/dist/components/profile/change-phone-form.js.map +1 -1
  55. package/dist/components/profile/change-profile.d.ts +2 -1
  56. package/dist/components/profile/change-profile.js +16 -8
  57. package/dist/components/profile/change-profile.js.map +1 -1
  58. package/dist/components/profile/otp-verification-modal.js +24 -27
  59. package/dist/components/profile/otp-verification-modal.js.map +1 -1
  60. package/dist/components/profile/security.js +88 -57
  61. package/dist/components/profile/security.js.map +1 -1
  62. package/dist/components/profile/verify-change-email-form.js +24 -27
  63. package/dist/components/profile/verify-change-email-form.js.map +1 -1
  64. package/dist/components/profile/verify-change-phone-form.js +24 -27
  65. package/dist/components/profile/verify-change-phone-form.js.map +1 -1
  66. package/dist/index.d.ts +9 -1
  67. package/dist/index.js +1897 -821
  68. package/dist/index.js.map +1 -1
  69. package/dist/pages/auth/forgot-password.d.ts +7 -0
  70. package/dist/pages/auth/forgot-password.js +784 -0
  71. package/dist/pages/auth/forgot-password.js.map +1 -0
  72. package/dist/pages/auth/layout.d.ts +8 -0
  73. package/dist/pages/auth/layout.js +562 -0
  74. package/dist/pages/auth/layout.js.map +1 -0
  75. package/dist/pages/auth/reset-password.d.ts +10 -0
  76. package/dist/pages/auth/reset-password.js +913 -0
  77. package/dist/pages/auth/reset-password.js.map +1 -0
  78. package/dist/pages/auth/set-password.d.ts +10 -0
  79. package/dist/pages/auth/set-password.js +946 -0
  80. package/dist/pages/auth/set-password.js.map +1 -0
  81. package/dist/pages/auth/sign-in.d.ts +10 -0
  82. package/dist/pages/auth/sign-in.js +984 -0
  83. package/dist/pages/auth/sign-in.js.map +1 -0
  84. package/dist/pages/auth/sign-up.d.ts +10 -0
  85. package/dist/pages/auth/sign-up.js +940 -0
  86. package/dist/pages/auth/sign-up.js.map +1 -0
  87. package/dist/pages/auth/verify-email.d.ts +10 -0
  88. package/dist/pages/auth/verify-email.js +950 -0
  89. package/dist/pages/auth/verify-email.js.map +1 -0
  90. package/dist/pages/auth/verify-phone.d.ts +10 -0
  91. package/dist/pages/auth/verify-phone.js +964 -0
  92. package/dist/pages/auth/verify-phone.js.map +1 -0
  93. package/dist/pages/iam/permissions.d.ts +5 -0
  94. package/dist/pages/iam/permissions.js +308 -0
  95. package/dist/pages/iam/permissions.js.map +1 -0
  96. package/dist/pages/iam/role-detail-layout.d.ts +12 -0
  97. package/dist/pages/iam/role-detail-layout.js +145 -0
  98. package/dist/pages/iam/role-detail-layout.js.map +1 -0
  99. package/dist/pages/iam/role-detail.d.ts +12 -0
  100. package/dist/pages/iam/role-detail.js +241 -0
  101. package/dist/pages/iam/role-detail.js.map +1 -0
  102. package/dist/pages/iam/role-permissions.d.ts +12 -0
  103. package/dist/pages/iam/role-permissions.js +409 -0
  104. package/dist/pages/iam/role-permissions.js.map +1 -0
  105. package/dist/pages/iam/role-users.d.ts +12 -0
  106. package/dist/pages/iam/role-users.js +825 -0
  107. package/dist/pages/iam/role-users.js.map +1 -0
  108. package/dist/pages/iam/roles.d.ts +5 -0
  109. package/dist/pages/iam/roles.js +684 -0
  110. package/dist/pages/iam/roles.js.map +1 -0
  111. package/dist/pages/iam/sessions.d.ts +5 -0
  112. package/dist/pages/iam/sessions.js +315 -0
  113. package/dist/pages/iam/sessions.js.map +1 -0
  114. package/dist/pages/iam/tenant-detail.d.ts +10 -0
  115. package/dist/pages/iam/tenant-detail.js +186 -0
  116. package/dist/pages/iam/tenant-detail.js.map +1 -0
  117. package/dist/pages/iam/tenants.d.ts +5 -0
  118. package/dist/pages/iam/tenants.js +610 -0
  119. package/dist/pages/iam/tenants.js.map +1 -0
  120. package/dist/pages/iam/user-activity.d.ts +10 -0
  121. package/dist/pages/iam/user-activity.js +850 -0
  122. package/dist/pages/iam/user-activity.js.map +1 -0
  123. package/dist/pages/iam/user-detail-layout.d.ts +12 -0
  124. package/dist/pages/iam/user-detail-layout.js +106 -0
  125. package/dist/pages/iam/user-detail-layout.js.map +1 -0
  126. package/dist/pages/iam/user-detail.d.ts +10 -0
  127. package/dist/pages/iam/user-detail.js +102 -0
  128. package/dist/pages/iam/user-detail.js.map +1 -0
  129. package/dist/pages/iam/users.d.ts +5 -0
  130. package/dist/pages/iam/users.js +1275 -0
  131. package/dist/pages/iam/users.js.map +1 -0
  132. package/dist/pages/profile/account.d.ts +5 -0
  133. package/dist/pages/profile/account.js +182 -0
  134. package/dist/pages/profile/account.js.map +1 -0
  135. package/dist/pages/profile/layout.d.ts +8 -0
  136. package/dist/pages/profile/layout.js +133 -0
  137. package/dist/pages/profile/layout.js.map +1 -0
  138. package/dist/pages/profile/security.d.ts +5 -0
  139. package/dist/pages/profile/security.js +1539 -0
  140. package/dist/pages/profile/security.js.map +1 -0
  141. package/dist/{types-vcfvnAzQ.d.ts → types-g9QcNRxT.d.ts} +13 -7
  142. package/package.json +102 -3
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/components/profile/account.tsx","../../../src/provider.tsx","../../../src/utils/cookie.ts"],"sourcesContent":["'use client';\n\nimport { Separator } from '@mesob/ui/components';\nimport { useSession } from '../../provider';\n\nexport function Account() {\n const { user, isAuthenticated } = useSession();\n\n if (!(isAuthenticated && user)) {\n return <div>Sign in required</div>;\n }\n\n return (\n <div className=\"p-6 max-w-4xl\">\n <div className=\"mb-6\">\n <h2 className=\"text-lg font-semibold mb-4\">Profile details</h2>\n <Separator />\n </div>\n\n <div className=\"space-y-6 transition-all duration-300 ease-in-out\">\n {/* Profile Section */}\n <div className=\"flex flex-col md:flex-row items-start gap-4 md:gap-12 min-h-[3rem]\">\n <div className=\"w-full md:w-48 mt-4 shrink-0 h-fit\">\n <span className=\"font-medium text-sm\">Profile</span>\n </div>\n </div>\n\n <Separator />\n\n {/* Email addresses Section */}\n <div className=\"flex flex-col md:flex-row gap-4 md:gap-12 py-2\">\n <div className=\"w-full md:w-48 shrink-0\">\n <span className=\"font-medium text-sm\">Email addresses</span>\n </div>\n <div className=\"flex-1 space-y-4\">\n <div className=\"flex items-center justify-between group\">\n {user.email ? (\n <div className=\"flex items-center gap-3\">\n <span className=\"text-sm\">{user.email}</span>\n </div>\n ) : (\n <span className=\"text-sm text-muted-foreground\">\n No email address\n </span>\n )}\n </div>\n </div>\n </div>\n\n <Separator />\n\n {/* Phone numbers Section */}\n <div className=\"flex flex-col md:flex-row gap-4 md:gap-12 py-2\">\n <div className=\"w-full md:w-48 shrink-0\">\n <span className=\"font-medium text-sm\">Phone numbers</span>\n </div>\n <div className=\"flex-1 space-y-4\">\n {user.phone ? (\n <div className=\"flex items-center justify-between\">\n <span className=\"text-sm\">{user.phone}</span>\n </div>\n ) : (\n <span className=\"text-sm text-muted-foreground\">\n No phone number\n </span>\n )}\n </div>\n </div>\n </div>\n </div>\n );\n}\n","'use client';\n\nimport { QueryClient, QueryClientProvider } from '@tanstack/react-query';\nimport { deepmerge } from 'deepmerge-ts';\nimport createFetchClient from 'openapi-fetch';\nimport createClient from 'openapi-react-query';\nimport type { ReactNode } from 'react';\nimport { createContext, useContext, useMemo, useState } from 'react';\nimport type { paths } from './data/openapi';\nimport { createTranslator } from './lib/translations';\nimport {\n type AuthClientConfig,\n type AuthResponse,\n defaultAuthClientConfig,\n type Session,\n type User,\n} from './types';\nimport { getSessionCookieName } from './utils/cookie';\nimport { createCustomFetch } from './utils/custom-fetch';\n\n// biome-ignore lint/suspicious/noExplicitAny: OpenAPI hooks type\ntype OpenApiHooks = any;\n\n// --- Utility: Check if running on server ---\nfunction isServer(): boolean {\n return typeof document === 'undefined';\n}\n\n/**\n * @deprecated Cookie is httpOnly and cannot be read client-side.\n * Use `useSession().isAuthenticated` instead.\n * This function always returns false on client.\n */\nexport function hasAuthCookie(_cookieName: string): boolean {\n // Cookie is httpOnly, can't check client-side\n // Always return false - use useSession() for auth status\n return false;\n}\n\n// --- Types ---\nexport type AuthStatus = 'loading' | 'authenticated' | 'unauthenticated';\n\ntype AuthState = {\n user: User | null;\n session: Session | null;\n status: AuthStatus;\n error: Error | null;\n};\n\ntype SessionContextValue = AuthState & {\n isLoading: boolean;\n isAuthenticated: boolean;\n refresh: () => Promise<void>;\n signOut: () => Promise<void>;\n};\n\ntype ApiContextValue = {\n hooks: OpenApiHooks;\n setAuth: (auth: AuthResponse) => void;\n clearAuth: () => void;\n refresh: () => Promise<void>;\n};\n\ntype ConfigContextValue = {\n config: AuthClientConfig;\n cookieName: string;\n t: (key: string, params?: Record<string, string | number>) => string;\n};\n\nconst SessionContext = createContext<SessionContextValue | null>(null);\nconst ApiContext = createContext<ApiContextValue | null>(null);\nconst ConfigContext = createContext<ConfigContextValue | null>(null);\n\nconst queryClient = new QueryClient({\n defaultOptions: {\n queries: {\n refetchOnWindowFocus: false,\n },\n },\n});\n\n// --- Hooks ---\n\n/**\n * Get session state including user, session, and auth status.\n * - `status`: 'loading' | 'authenticated' | 'unauthenticated'\n * - `isLoading`: true while fetching session\n * - `isAuthenticated`: true if user and session exist\n */\nexport function useSession(): SessionContextValue {\n const context = useContext(SessionContext);\n if (!context) {\n throw new Error('useSession must be used within MesobAuthProvider');\n }\n return context;\n}\n\nexport function useApi(): ApiContextValue {\n const context = useContext(ApiContext);\n if (!context) {\n throw new Error('useApi must be used within MesobAuthProvider');\n }\n return context;\n}\n\nexport function useConfig(): ConfigContextValue {\n const context = useContext(ConfigContext);\n if (!context) {\n throw new Error('useConfig must be used within MesobAuthProvider');\n }\n return context;\n}\n\n/**\n * @deprecated Cookie is httpOnly, can't be checked client-side.\n * Use `useSession().isAuthenticated` instead.\n */\nexport function useHasAuthCookie(): boolean {\n const { status } = useSession();\n return status === 'authenticated' || status === 'loading';\n}\n\n// --- Provider ---\n\ntype MesobAuthProviderProps = {\n config: AuthClientConfig;\n children: ReactNode;\n};\n\nexport function MesobAuthProvider({\n config,\n children,\n}: MesobAuthProviderProps) {\n const mergedConfig = useMemo(\n () =>\n deepmerge(\n { ...defaultAuthClientConfig } as Partial<AuthClientConfig>,\n config,\n ) as AuthClientConfig,\n [config],\n );\n\n const api = useMemo(\n () =>\n createFetchClient<paths>({\n baseUrl: mergedConfig.baseURL,\n fetch: createCustomFetch(mergedConfig),\n }),\n [mergedConfig],\n );\n\n const hooks = useMemo(() => createClient(api), [api]);\n const cookieName = useMemo(\n () => getSessionCookieName(mergedConfig),\n [mergedConfig],\n );\n\n return (\n <QueryClientProvider client={queryClient}>\n <AuthStateProvider\n config={mergedConfig}\n hooks={hooks}\n cookieName={cookieName}\n >\n {children}\n </AuthStateProvider>\n </QueryClientProvider>\n );\n}\n\ntype AuthStateProviderProps = {\n config: AuthClientConfig;\n hooks: OpenApiHooks;\n cookieName: string;\n children: ReactNode;\n};\n\nfunction AuthStateProvider({\n config,\n hooks,\n cookieName,\n children,\n}: AuthStateProviderProps) {\n // Manual override for sign-out / sign-in\n const [override, setOverride] = useState<AuthState | null>(null);\n\n // Always fetch session - cookie is httpOnly, can't check client-side\n // Server will read the cookie and return user/session if valid\n const {\n data: sessionData,\n isLoading,\n isFetched,\n error: sessionError,\n refetch,\n } = hooks.useQuery(\n 'get',\n '/session',\n {},\n {\n enabled: !(override || isServer()),\n refetchOnMount: false,\n refetchOnWindowFocus: false,\n refetchOnReconnect: false,\n retry: false,\n gcTime: 0,\n staleTime: 0,\n },\n );\n\n // Derive state directly - no useEffect\n const user = override?.user ?? sessionData?.user ?? null;\n const session = override?.session ?? sessionData?.session ?? null;\n const error = override?.error ?? (sessionError as Error | null);\n\n // Check error status code\n const errorStatus = (() => {\n if (!sessionError) {\n return null;\n }\n const err = sessionError as { status?: number };\n return err.status ?? null;\n })();\n\n // Check if error is a network/connection error\n const isNetworkError = (() => {\n if (!sessionError) {\n return false;\n }\n const error = sessionError as Error & { cause?: unknown; data?: unknown };\n const errorMessage =\n error.message || String(error) || JSON.stringify(error);\n // Network errors: TypeError, DOMException, or fetch failures\n if (\n error instanceof TypeError ||\n error instanceof DOMException ||\n error.name === 'TypeError' ||\n errorMessage.includes('Failed to fetch') ||\n errorMessage.includes('ERR_CONNECTION_REFUSED') ||\n errorMessage.includes('NetworkError') ||\n errorMessage.includes('Network request failed') ||\n errorMessage.includes('fetch failed')\n ) {\n return true;\n }\n // Check error cause\n if (error.cause) {\n const causeStr = String(error.cause);\n if (\n causeStr.includes('Failed to fetch') ||\n causeStr.includes('ERR_CONNECTION_REFUSED') ||\n causeStr.includes('NetworkError')\n ) {\n return true;\n }\n }\n return false;\n })();\n\n // Compute status\n // biome-ignore lint: Status determination requires multiple checks\n const status: AuthStatus = (() => {\n if (override) {\n return override.status;\n }\n if (isServer()) {\n return 'loading';\n }\n if (user && session) {\n return 'authenticated';\n }\n // Check for network errors or auth errors first - allow auth page to show\n if (isNetworkError || errorStatus === 401) {\n return 'unauthenticated';\n }\n // If we have an error but it's not a network error, still check loading state\n if (sessionError && !isNetworkError && errorStatus !== 401) {\n if (errorStatus && errorStatus >= 500) {\n return 'authenticated';\n }\n // Other errors mean unauthenticated\n if (isFetched) {\n return 'unauthenticated';\n }\n }\n if (isLoading || !isFetched) {\n return 'loading';\n }\n if (isFetched && !user && !session) {\n return 'unauthenticated';\n }\n return 'unauthenticated';\n })();\n\n const signOutMutation = hooks.useMutation('post', '/sign-out');\n const t = createTranslator(config.messages || {});\n\n const setAuth = (auth: AuthResponse) => {\n setOverride({\n user: auth.user,\n session: auth.session,\n status: 'authenticated',\n error: null,\n });\n };\n\n const clearAuth = () => {\n setOverride({\n user: null,\n session: null,\n status: 'unauthenticated',\n error: null,\n });\n };\n\n const refresh = async () => {\n setOverride(null);\n await refetch();\n };\n\n const signOut = async () => {\n try {\n await signOutMutation.mutateAsync({});\n } finally {\n clearAuth();\n }\n };\n\n return (\n <ConfigContext.Provider value={{ config, cookieName, t }}>\n <ApiContext.Provider value={{ hooks, setAuth, clearAuth, refresh }}>\n <SessionContext.Provider\n value={{\n user,\n session,\n status,\n error,\n isLoading: status === 'loading',\n isAuthenticated: status === 'authenticated',\n refresh,\n signOut,\n }}\n >\n {children}\n </SessionContext.Provider>\n </ApiContext.Provider>\n </ConfigContext.Provider>\n );\n}\n","import type { AuthClientConfig } from '../types';\n\nconst isProduction =\n typeof process !== 'undefined' && process.env.NODE_ENV === 'production';\n\nexport const getSessionCookieName = (config: AuthClientConfig): string => {\n const prefix = config.cookiePrefix || '';\n const baseName = 'session_token';\n if (prefix) {\n return `${prefix}_${baseName}`;\n }\n return isProduction ? '__Host-session_token' : baseName;\n};\n"],"mappings":";;;AAEA,SAAS,iBAAiB;;;ACA1B,SAAS,aAAa,2BAA2B;AACjD,SAAS,iBAAiB;AAC1B,OAAO,uBAAuB;AAC9B,OAAO,kBAAkB;AAEzB,SAAS,eAAe,YAAY,SAAS,gBAAgB;;;ACL7D,IAAM,eACJ,OAAO,YAAY,eAAe,QAAQ,IAAI,aAAa;;;AD4JvD;AA1FN,IAAM,iBAAiB,cAA0C,IAAI;AACrE,IAAM,aAAa,cAAsC,IAAI;AAC7D,IAAM,gBAAgB,cAAyC,IAAI;AAEnE,IAAM,cAAc,IAAI,YAAY;AAAA,EAClC,gBAAgB;AAAA,IACd,SAAS;AAAA,MACP,sBAAsB;AAAA,IACxB;AAAA,EACF;AACF,CAAC;AAUM,SAAS,aAAkC;AAChD,QAAM,UAAU,WAAW,cAAc;AACzC,M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AA,KAAC,UAAK,WAAU,WAAW,eAAK,OAAM,GACxC,IAEA,gBAAAA,KAAC,UAAK,WAAU,iCAAgC,6BAEhD,GAEJ;AAAA,SACF;AAAA,OACF;AAAA,KACF;AAEJ;","names":["jsx"]}
1
+ {"version":3,"sources":["../../../src/components/profile/account.tsx","../../../src/provider.tsx","../../../src/utils/cookie.ts","../../../src/components/profile/change-profile.tsx"],"sourcesContent":["'use client';\n\nimport { Badge, Card, CardContent, Separator } from '@mesob/ui/components';\nimport { useSession } from '../../provider';\nimport { ChangeProfile } from './change-profile';\n\nexport function Account() {\n const { user, isAuthenticated } = useSession();\n\n if (!(isAuthenticated && user)) {\n return (\n <div className=\"rounded-[1.75rem] border border-dashed border-border bg-muted/30 p-8 text-sm text-muted-foreground\">\n Sign in required.\n </div>\n );\n }\n\n const contactItems = [\n {\n label: 'Email',\n value: user.email ?? 'No email address',\n status: user.emailVerified ? 'Verified' : 'Needs verification',\n },\n {\n label: 'Phone',\n value: user.phone ?? 'No phone number',\n status: user.phoneVerified ? 'Verified' : 'Needs verification',\n },\n ];\n\n return (\n <div className=\"mx-auto flex w-full max-w-6xl flex-col gap-6\">\n <div className=\"relative overflow-hidden rounded-[2rem] border border-border/60 bg-gradient-to-br from-background via-background to-primary/5 p-6 shadow-sm\">\n <div className=\"absolute inset-y-0 right-0 w-1/3 bg-[radial-gradient(circle_at_top,_hsl(var(--primary)/0.16),_transparent_60%)]\" />\n <div className=\"relative flex flex-col gap-5\">\n <div className=\"flex flex-wrap items-center gap-2\">\n <Badge variant=\"outline\">Profile console</Badge>\n <Badge variant=\"secondary\">Live session data</Badge>\n </div>\n <div className=\"max-w-2xl space-y-2\">\n <h2 className=\"text-2xl font-semibold tracking-tight\">\n Account details, contact state, and verification status.\n </h2>\n <p className=\"text-sm text-muted-foreground\">\n Keep the identity surface minimal here. Contact updates and\n sensitive changes stay in security.\n </p>\n </div>\n <ChangeProfile user={user} />\n </div>\n </div>\n\n <div className=\"grid gap-4 lg:grid-cols-[1.5fr_0.9fr]\">\n <Card className=\"rounded-[1.75rem] border-border/60 shadow-sm\">\n <CardContent className=\"space-y-5 p-6\">\n <div className=\"space-y-1\">\n <div className=\"text-sm font-medium text-muted-foreground\">\n Contact channels\n </div>\n <div className=\"text-lg font-semibold\">Primary profile data</div>\n </div>\n <Separator />\n <div className=\"space-y-4\">\n {contactItems.map((item) => (\n <div\n key={item.label}\n className=\"flex flex-col gap-3 rounded-2xl border border-border/60 bg-muted/20 p-4 md:flex-row md:items-center md:justify-between\"\n >\n <div className=\"space-y-1\">\n <div className=\"text-sm font-medium\">{item.label}</div>\n <div className=\"text-sm text-muted-foreground\">\n {item.value}\n </div>\n </div>\n <Badge variant=\"outline\">{item.status}</Badge>\n </div>\n ))}\n </div>\n </CardContent>\n </Card>\n\n <Card className=\"rounded-[1.75rem] border-border/60 shadow-sm\">\n <CardContent className=\"space-y-5 p-6\">\n <div className=\"space-y-1\">\n <div className=\"text-sm font-medium text-muted-foreground\">\n Snapshot\n </div>\n <div className=\"text-lg font-semibold\">\n Session-facing identity\n </div>\n </div>\n <Separator />\n <div className=\"grid gap-3\">\n <div className=\"rounded-2xl bg-primary/[0.06] p-4\">\n <div className=\"text-xs uppercase tracking-[0.18em] text-muted-foreground\">\n Full name\n </div>\n <div className=\"mt-2 text-base font-semibold\">\n {user.fullName}\n </div>\n </div>\n <div className=\"rounded-2xl bg-muted/25 p-4\">\n <div className=\"text-xs uppercase tracking-[0.18em] text-muted-foreground\">\n Last sign in\n </div>\n <div className=\"mt-2 text-base font-semibold\">\n {user.lastSignInAt\n ? new Date(user.lastSignInAt).toLocaleString()\n : 'No activity recorded'}\n </div>\n </div>\n </div>\n </CardContent>\n </Card>\n </div>\n </div>\n );\n}\n","'use client';\n\nimport { QueryClient, QueryClientProvider } from '@tanstack/react-query';\nimport { deepmerge } from 'deepmerge-ts';\nimport createFetchClient from 'openapi-fetch';\nimport createClient from 'openapi-react-query';\nimport type { ReactNode } from 'react';\nimport { createContext, useContext, useMemo, useState } from 'react';\nimport type { paths } from './data/openapi';\nimport { createTranslator } from './lib/translations';\nimport {\n type AuthClientConfig,\n type AuthResponse,\n defaultAuthClientConfig,\n type Session,\n type User,\n} from './types';\nimport { getSessionCookieName } from './utils/cookie';\nimport { createCustomFetch } from './utils/custom-fetch';\n\n// biome-ignore lint/suspicious/noExplicitAny: OpenAPI hooks type\ntype OpenApiHooks = any;\n\n// --- Utility: Check if running on server ---\nfunction isServer(): boolean {\n return typeof document === 'undefined';\n}\n\n/**\n * @deprecated Cookie is httpOnly and cannot be read client-side.\n * Use `useSession().isAuthenticated` instead.\n * This function always returns false on client.\n */\nexport function hasAuthCookie(_cookieName: string): boolean {\n // Cookie is httpOnly, can't check client-side\n // Always return false - use useSession() for auth status\n return false;\n}\n\n// --- Types ---\nexport type AuthStatus = 'loading' | 'authenticated' | 'unauthenticated';\n\ntype AuthState = {\n user: User | null;\n session: Session | null;\n status: AuthStatus;\n error: Error | null;\n};\n\ntype SessionContextValue = AuthState & {\n isLoading: boolean;\n isAuthenticated: boolean;\n refresh: () => Promise<void>;\n signOut: () => Promise<void>;\n};\n\ntype ApiContextValue = {\n hooks: OpenApiHooks;\n setAuth: (auth: AuthResponse) => void;\n clearAuth: () => void;\n refresh: () => Promise<void>;\n};\n\ntype ConfigContextValue = {\n config: AuthClientConfig;\n cookieName: string;\n t: (key: string, params?: Record<string, string | number>) => string;\n};\n\nconst SessionContext = createContext<SessionContextValue | null>(null);\nconst ApiContext = createContext<ApiContextValue | null>(null);\nconst ConfigContext = createContext<ConfigContextValue | null>(null);\n\nconst queryClient = new QueryClient({\n defaultOptions: {\n queries: {\n refetchOnWindowFocus: false,\n },\n },\n});\n\n// --- Hooks ---\n\n/**\n * Get session state including user, session, and auth status.\n * - `status`: 'loading' | 'authenticated' | 'unauthenticated'\n * - `isLoading`: true while fetching session\n * - `isAuthenticated`: true if user and session exist\n */\nexport function useSession(): SessionContextValue {\n const context = useContext(SessionContext);\n if (!context) {\n throw new Error('useSession must be used within MesobAuthProvider');\n }\n return context;\n}\n\nexport function useApi(): ApiContextValue {\n const context = useContext(ApiContext);\n if (!context) {\n throw new Error('useApi must be used within MesobAuthProvider');\n }\n return context;\n}\n\nexport function useConfig(): ConfigContextValue {\n const context = useContext(ConfigContext);\n if (!context) {\n throw new Error('useConfig must be used within MesobAuthProvider');\n }\n return context;\n}\n\n/**\n * @deprecated Cookie is httpOnly, can't be checked client-side.\n * Use `useSession().isAuthenticated` instead.\n */\nexport function useHasAuthCookie(): boolean {\n const { status } = useSession();\n return status === 'authenticated' || status === 'loading';\n}\n\n// --- Provider ---\n\ntype MesobAuthProviderProps = {\n config: AuthClientConfig;\n children: ReactNode;\n};\n\nexport function MesobAuthProvider({\n config,\n children,\n}: MesobAuthProviderProps) {\n const mergedConfig = useMemo(\n () =>\n deepmerge(\n { ...defaultAuthClientConfig } as Partial<AuthClientConfig>,\n config,\n ) as AuthClientConfig,\n [config],\n );\n\n const api = useMemo(\n () =>\n createFetchClient<paths>({\n baseUrl: mergedConfig.baseURL,\n fetch: createCustomFetch(mergedConfig),\n }),\n [mergedConfig],\n );\n\n const hooks = useMemo(() => createClient(api), [api]);\n const cookieName = useMemo(\n () => getSessionCookieName(mergedConfig),\n [mergedConfig],\n );\n\n return (\n <QueryClientProvider client={queryClient}>\n <AuthStateProvider\n config={mergedConfig}\n hooks={hooks}\n cookieName={cookieName}\n >\n {children}\n </AuthStateProvider>\n </QueryClientProvider>\n );\n}\n\ntype AuthStateProviderProps = {\n config: AuthClientConfig;\n hooks: OpenApiHooks;\n cookieName: string;\n children: ReactNode;\n};\n\nfunction AuthStateProvider({\n config,\n hooks,\n cookieName,\n children,\n}: AuthStateProviderProps) {\n // Manual override for sign-out / sign-in\n const [override, setOverride] = useState<AuthState | null>(null);\n\n // Always fetch session - cookie is httpOnly, can't check client-side\n // Server will read the cookie and return user/session if valid\n const {\n data: sessionData,\n isLoading,\n isFetched,\n error: sessionError,\n refetch,\n } = hooks.useQuery(\n 'get',\n '/session',\n {},\n {\n enabled: !(override || isServer()),\n refetchOnMount: false,\n refetchOnWindowFocus: false,\n refetchOnReconnect: false,\n retry: false,\n gcTime: 0,\n staleTime: 0,\n },\n );\n\n // Derive state directly - no useEffect\n const user = override?.user ?? sessionData?.user ?? null;\n const session = override?.session ?? sessionData?.session ?? null;\n const error = override?.error ?? (sessionError as Error | null);\n\n // Check error status code\n const errorStatus = (() => {\n if (!sessionError) {\n return null;\n }\n const err = sessionError as { status?: number };\n return err.status ?? null;\n })();\n\n // Check if error is a network/connection error\n const isNetworkError = (() => {\n if (!sessionError) {\n return false;\n }\n const error = sessionError as Error & { cause?: unknown; data?: unknown };\n const errorMessage =\n error.message || String(error) || JSON.stringify(error);\n // Network errors: TypeError, DOMException, or fetch failures\n if (\n error instanceof TypeError ||\n error instanceof DOMException ||\n error.name === 'TypeError' ||\n errorMessage.includes('Failed to fetch') ||\n errorMessage.includes('ERR_CONNECTION_REFUSED') ||\n errorMessage.includes('NetworkError') ||\n errorMessage.includes('Network request failed') ||\n errorMessage.includes('fetch failed')\n ) {\n return true;\n }\n // Check error cause\n if (error.cause) {\n const causeStr = String(error.cause);\n if (\n causeStr.includes('Failed to fetch') ||\n causeStr.includes('ERR_CONNECTION_REFUSED') ||\n causeStr.includes('NetworkError')\n ) {\n return true;\n }\n }\n return false;\n })();\n\n // Compute status\n // biome-ignore lint: Status determination requires multiple checks\n const status: AuthStatus = (() => {\n if (override) {\n return override.status;\n }\n if (isServer()) {\n return 'loading';\n }\n if (user && session) {\n return 'authenticated';\n }\n // Check for network errors or auth errors first - allow auth page to show\n if (isNetworkError || errorStatus === 401) {\n return 'unauthenticated';\n }\n // If we have an error but it's not a network error, still check loading state\n if (sessionError && !isNetworkError && errorStatus !== 401) {\n if (errorStatus && errorStatus >= 500) {\n return 'authenticated';\n }\n // Other errors mean unauthenticated\n if (isFetched) {\n return 'unauthenticated';\n }\n }\n if (isLoading || !isFetched) {\n return 'loading';\n }\n if (isFetched && !user && !session) {\n return 'unauthenticated';\n }\n return 'unauthenticated';\n })();\n\n const signOutMutation = hooks.useMutation('post', '/sign-out');\n const t = createTranslator(config.messages || {});\n\n const setAuth = (auth: AuthResponse) => {\n setOverride({\n user: auth.user,\n session: auth.session,\n status: 'authenticated',\n error: null,\n });\n };\n\n const clearAuth = () => {\n setOverride({\n user: null,\n session: null,\n status: 'unauthenticated',\n error: null,\n });\n };\n\n const refresh = async () => {\n setOverride(null);\n await refetch();\n };\n\n const signOut = async () => {\n try {\n await signOutMutation.mutateAsync({});\n } finally {\n clearAuth();\n }\n };\n\n return (\n <ConfigContext.Provider value={{ config, cookieName, t }}>\n <ApiContext.Provider value={{ hooks, setAuth, clearAuth, refresh }}>\n <SessionContext.Provider\n value={{\n user,\n session,\n status,\n error,\n isLoading: status === 'loading',\n isAuthenticated: status === 'authenticated',\n refresh,\n signOut,\n }}\n >\n {children}\n </SessionContext.Provider>\n </ApiContext.Provider>\n </ConfigContext.Provider>\n );\n}\n","import type { AuthClientConfig } from '../types';\n\nconst isProduction =\n typeof process !== 'undefined' && process.env.NODE_ENV === 'production';\n\nexport const getSessionCookieName = (config: AuthClientConfig): string => {\n const prefix = config.cookiePrefix || '';\n const baseName = 'session_token';\n if (prefix) {\n return `${prefix}_${baseName}`;\n }\n return isProduction ? '__Host-session_token' : baseName;\n};\n","import {\n Avatar,\n AvatarFallback,\n AvatarImage,\n Badge,\n Button,\n} from '@mesob/ui/components';\nimport { useState } from 'react';\nimport type { User } from '../../types';\n\ntype Props = {\n user: User;\n};\n\nexport const ChangeProfile = ({ user }: Props) => {\n const [isEditing, setIsEditing] = useState(false);\n const initials =\n user.fullName\n ?.split(' ')\n .map((part) => part[0])\n .join('')\n .toUpperCase()\n .slice(0, 2) || 'U';\n\n return (\n <div className=\"w-full rounded-[1.5rem] border border-border/60 bg-background/80 p-5 shadow-sm backdrop-blur\">\n <div className=\"flex flex-col gap-4 md:flex-row md:items-center md:justify-between\">\n <div className=\"flex items-center gap-4\">\n <Avatar className=\"h-14 w-14 ring-4 ring-primary/10\">\n <AvatarImage src={user.image || ''} alt={user.fullName || ''} />\n <AvatarFallback>{initials}</AvatarFallback>\n </Avatar>\n <div className=\"space-y-1\">\n <div className=\"text-base font-semibold\">{user.fullName}</div>\n <div className=\"flex flex-wrap gap-2 text-xs text-muted-foreground\">\n <Badge variant=\"outline\">\n {user.emailVerified ? 'Email verified' : 'Email unverified'}\n </Badge>\n <Badge variant=\"outline\">\n {user.phoneVerified ? 'Phone verified' : 'Phone unverified'}\n </Badge>\n </div>\n </div>\n </div>\n <Button\n variant=\"secondary\"\n className=\"rounded-full px-5 text-primary hover:text-primary/80\"\n onClick={() => setIsEditing((v) => !v)}\n >\n {isEditing ? 'Hide editor' : 'Update profile'}\n </Button>\n </div>\n {isEditing && (\n <div className=\"mt-4 rounded-2xl border border-dashed border-border bg-muted/30 px-4 py-3 text-sm text-muted-foreground\">\n Profile editing is not wired yet. Contact and password flows below are\n live.\n </div>\n )}\n </div>\n );\n};\n"],"mappings":";;;AAEA,SAAS,SAAAA,QAAO,MAAM,aAAa,iBAAiB;;;ACApD,SAAS,aAAa,2BAA2B;AACjD,SAAS,iBAAiB;AAC1B,OAAO,uBAAuB;AAC9B,OAAO,kBAAkB;AAEzB,SAAS,eAAe,YAAY,SAAS,gBAAgB;;;ACL7D,IAAM,eACJ,OAAO,YAAY,eAAe,QAAQ,IAAI,aAAa;;;AD4JvD;AA1FN,IAAM,iBAAiB,cAA0C,IAAI;AACrE,IAAM,aAAa,cAAsC,IAAI;AAC7D,IAAM,gBAAgB,cAAyC,IAAI;AAEnE,IAAM,cAAc,IAAI,YAAY;AAAA,EAClC,gBAAgB;AAAA,IACd,SAAS;AAAA,MACP,sBAAsB;AAAA,IACxB;AAAA,EACF;AACF,CAAC;AAUM,SAAS,aAAkC;AAChD,QAAM,UAAU,WAAW,cAAc;AACzC,MAAI,CAAC,SAAS;AACZ,UAAM,IAAI,MAAM,kDAAkD;AAAA,EACpE;AACA,SAAO;AAC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2
 
3
3
  // src/components/profile/change-email-form.tsx
4
4
  import {
5
- Button as Button4,
5
+ Button as Button3,
6
6
  Collapsible,
7
7
  CollapsibleContent,
8
8
  CollapsibleTrigger
@@ -342,7 +342,7 @@ import {
342
342
  // src/components/auth/verification-form.tsx
343
343
  import { zodResolver as zodResolver2 } from "@hookform/resolvers/zod";
344
344
  import {
345
- Button as Button3,
345
+ Button as Button2,
346
346
  Form,
347
347
  FormControl,
348
348
  FormField,
@@ -351,8 +351,7 @@ import {
351
351
  FormMessage,
352
352
  InputOTP,
353
353
  InputOTPGroup,
354
- InputOTPSlot,
355
- Spinner as Spinner3
354
+ InputOTPSlot
356
355
  } from "@mesob/ui/components";
357
356
  import { useForm as useForm2 } from "react-hook-form";
358
357
  import { z as z2 } from "zod";
@@ -372,7 +371,7 @@ function useTranslator(namespace) {
372
371
  }
373
372
 
374
373
  // src/components/auth/countdown.tsx
375
- import { Button as Button2, Spinner as Spinner2 } from "@mesob/ui/components";
374
+ import { Spinner as Spinner2 } from "@mesob/ui/components";
376
375
  import { useEffect as useEffect2, useState as useState3 } from "react";
377
376
  import { jsx as jsx3, jsxs as jsxs2 } from "react/jsx-runtime";
378
377
  var Countdown = ({
@@ -408,17 +407,19 @@ var Countdown = ({
408
407
  setIsResending(false);
409
408
  }
410
409
  };
410
+ const busy = isResending || resending;
411
411
  if (seconds > 0) {
412
- return /* @__PURE__ */ jsx3(Button2, { variant: "ghost", disabled: true, children: t("resendIn", { seconds }) });
412
+ return /* @__PURE__ */ jsx3("p", { className: "text-sm text-muted-foreground", children: t("resendIn", { seconds }) });
413
413
  }
414
414
  return /* @__PURE__ */ jsxs2(
415
- Button2,
415
+ "button",
416
416
  {
417
- variant: "ghost",
417
+ type: "button",
418
418
  onClick: handleResend,
419
- disabled: isResending || resending,
419
+ disabled: busy,
420
+ className: "text-sm text-primary hover:underline disabled:opacity-50 flex items-center gap-1",
420
421
  children: [
421
- isResending || resending && /* @__PURE__ */ jsx3(Spinner2, {}),
422
+ busy && /* @__PURE__ */ jsx3(Spinner2, { className: "h-3 w-3" }),
422
423
  t("resend")
423
424
  ]
424
425
  }
@@ -438,13 +439,12 @@ var VerificationForm = ({
438
439
  const t = useTranslator("Auth.verification");
439
440
  const form = useForm2({
440
441
  resolver: zodResolver2(verificationSchema(t)),
441
- defaultValues: {
442
- code: ""
443
- }
442
+ defaultValues: { code: "" }
444
443
  });
445
444
  const handleSubmit = form.handleSubmit(async (values) => {
446
445
  await onSubmit(values);
447
446
  });
447
+ const codeLength = form.watch("code").length;
448
448
  return /* @__PURE__ */ jsx4(Form, { ...form, children: /* @__PURE__ */ jsxs3(
449
449
  "form",
450
450
  {
@@ -482,21 +482,18 @@ var VerificationForm = ({
482
482
  ] })
483
483
  }
484
484
  ),
485
- /* @__PURE__ */ jsxs3("div", { className: "flex justify-between items-center", children: [
486
- /* @__PURE__ */ jsx4(Countdown, { onResend, resending: isLoading }),
487
- /* @__PURE__ */ jsxs3(
488
- Button3,
489
- {
490
- type: "submit",
491
- form: "verification-form",
492
- disabled: isLoading || form.watch("code").length !== 6,
493
- children: [
494
- isLoading && /* @__PURE__ */ jsx4(Spinner3, {}),
495
- t("form.confirm")
496
- ]
497
- }
498
- )
499
- ] })
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 }) })
500
497
  ]
501
498
  }
502
499
  ) });
@@ -700,7 +697,7 @@ function ChangeEmailForm() {
700
697
  CollapsibleTrigger,
701
698
  {
702
699
  render: /* @__PURE__ */ jsx7(
703
- Button4,
700
+ Button3,
704
701
  {
705
702
  variant: "ghost",
706
703
  className: "w-full justify-between p-4 h-auto"
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/components/profile/change-email-form.tsx","../../../src/provider.tsx","../../../src/lib/translations.ts","../../../src/utils/cookie.ts","../../../src/components/profile/request-change-email-form.tsx","../../../src/components/profile/verify-change-email-form.tsx","../../../src/components/profile/otp-verification-modal.tsx","../../../src/components/auth/verification-form.tsx","../../../src/hooks/use-translator.ts","../../../src/components/auth/countdown.tsx"],"sourcesContent":["'use client';\n\nimport {\n Button,\n Collapsible,\n CollapsibleContent,\n CollapsibleTrigger,\n} from '@mesob/ui/components';\nimport { IconChevronDown } from '@tabler/icons-react';\nimport { useState } from 'react';\nimport { useSession } from '../../provider';\nimport { RequestChangeEmailForm } from './request-change-email-form';\nimport { VerifyChangeEmailForm } from './verify-change-email-form';\n\nexport function ChangeEmailForm() {\n const { user } = useSession();\n const [isOpen, setIsOpen] = useState(false);\n const [showOtp, setShowOtp] = useState(false);\n const [verificationId, setVerificationId] = useState<string | null>(null);\n const [newEmail, setNewEmail] = useState<string>('');\n\n const resetForms = () => {\n setShowOtp(false);\n setVerificationId(null);\n setNewEmail('');\n };\n\n const handleRequestSuccess = (id: string, email: string) => {\n setVerificationId(id);\n setNewEmail(email);\n setShowOtp(true);\n };\n\n const handleVerifySuccess = () => {\n resetForms();\n setIsOpen(false);\n };\n\n const handleCancel = () => {\n resetForms();\n setIsOpen(false);\n };\n\n const title = user?.email ? 'Change Email' : 'Add Email';\n const description = user?.email\n ? 'Update your email address'\n : 'Add an email address to your account';\n return (\n <Collapsible open={isOpen} onOpenChange={setIsOpen}>\n <div className=\"border rounded-lg\">\n <CollapsibleTrigger\n render={\n <Button\n variant=\"ghost\"\n className=\"w-full justify-between p-4 h-auto\"\n />\n }\n >\n <div className=\"flex flex-col items-start\">\n <span className=\"font-medium\">{title}</span>\n <span className=\"text-sm text-muted-foreground\">{description}</span>\n </div>\n <IconChevronDown\n className={`h-4 w-4 transition-transform ${\n isOpen ? 'rotate-180' : ''\n }`}\n />\n </CollapsibleTrigger>\n\n <CollapsibleContent>\n {showOtp ? (\n <VerifyChangeEmailForm\n email={newEmail}\n verificationId={verificationId}\n onSuccess={handleVerifySuccess}\n onCancel={handleCancel}\n />\n ) : (\n <RequestChangeEmailForm\n onSuccess={handleRequestSuccess}\n onCancel={handleCancel}\n buttonText={title}\n />\n )}\n </CollapsibleContent>\n </div>\n </Collapsible>\n );\n}\n","'use client';\n\nimport { QueryClient, QueryClientProvider } from '@tanstack/react-query';\nimport { deepmerge } from 'deepmerge-ts';\nimport createFetchClient from 'openapi-fetch';\nimport createClient from 'openapi-react-query';\nimport type { ReactNode } from 'react';\nimport { createContext, useContext, useMemo, useState } from 'react';\nimport type { paths } from './data/openapi';\nimport { createTranslator } from './lib/translations';\nimport {\n type AuthClientConfig,\n type AuthResponse,\n defaultAuthClientConfig,\n type Session,\n type User,\n} from './types';\nimport { getSessionCookieName } from './utils/cookie';\nimport { createCustomFetch } from './utils/custom-fetch';\n\n// biome-ignore lint/suspicious/noExplicitAny: OpenAPI hooks type\ntype OpenApiHooks = any;\n\n// --- Utility: Check if running on server ---\nfunction isServer(): boolean {\n return typeof document === 'undefined';\n}\n\n/**\n * @deprecated Cookie is httpOnly and cannot be read client-side.\n * Use `useSession().isAuthenticated` instead.\n * This function always returns false on client.\n */\nexport function hasAuthCookie(_cookieName: string): boolean {\n // Cookie is httpOnly, can't check client-side\n // Always return false - use useSession() for auth status\n return false;\n}\n\n// --- Types ---\nexport type AuthStatus = 'loading' | 'authenticated' | 'unauthenticated';\n\ntype AuthState = {\n user: User | null;\n session: Session | null;\n status: AuthStatus;\n error: Error | null;\n};\n\ntype SessionContextValue = AuthState & {\n isLoading: boolean;\n isAuthenticated: boolean;\n refresh: () => Promise<void>;\n signOut: () => Promise<void>;\n};\n\ntype ApiContextValue = {\n hooks: OpenApiHooks;\n setAuth: (auth: AuthResponse) => void;\n clearAuth: () => void;\n refresh: () => Promise<void>;\n};\n\ntype ConfigContextValue = {\n config: AuthClientConfig;\n cookieName: string;\n t: (key: string, params?: Record<string, string | number>) => string;\n};\n\nconst SessionContext = createContext<SessionContextValue | null>(null);\nconst ApiContext = createContext<ApiContextValue | null>(null);\nconst ConfigContext = createContext<ConfigContextValue | null>(null);\n\nconst queryClient = new QueryClient({\n defaultOptions: {\n queries: {\n refetchOnWindowFocus: false,\n },\n },\n});\n\n// --- Hooks ---\n\n/**\n * Get session state including user, session, and auth status.\n * - `status`: 'loading' | 'authenticated' | 'unauthenticated'\n * - `isLoading`: true while fetching session\n * - `isAuthenticated`: true if user and session exist\n */\nexport function useSession(): SessionContextValue {\n const context = useContext(SessionContext);\n if (!context) {\n throw new Error('useSession must be used within MesobAuthProvider');\n }\n return context;\n}\n\nexport function useApi(): ApiContextValue {\n const context = useContext(ApiContext);\n if (!context) {\n throw new Error('useApi must be used within MesobAuthProvider');\n }\n return context;\n}\n\nexport function useConfig(): ConfigContextValue {\n const context = useContext(ConfigContext);\n if (!context) {\n throw new Error('useConfig must be used within MesobAuthProvider');\n }\n return context;\n}\n\n/**\n * @deprecated Cookie is httpOnly, can't be checked client-side.\n * Use `useSession().isAuthenticated` instead.\n */\nexport function useHasAuthCookie(): boolean {\n const { status } = useSession();\n return status === 'authenticated' || status === 'loading';\n}\n\n// --- Provider ---\n\ntype MesobAuthProviderProps = {\n config: AuthClientConfig;\n children: ReactNode;\n};\n\nexport function MesobAuthProvider({\n config,\n children,\n}: MesobAuthProviderProps) {\n const mergedConfig = useMemo(\n () =>\n deepmerge(\n { ...defaultAuthClientConfig } as Partial<AuthClientConfig>,\n config,\n ) as AuthClientConfig,\n [config],\n );\n\n const api = useMemo(\n () =>\n createFetchClient<paths>({\n baseUrl: mergedConfig.baseURL,\n fetch: createCustomFetch(mergedConfig),\n }),\n [mergedConfig],\n );\n\n const hooks = useMemo(() => createClient(api), [api]);\n const cookieName = useMemo(\n () => getSessionCookieName(mergedConfig),\n [mergedConfig],\n );\n\n return (\n <QueryClientProvider client={queryClient}>\n <AuthStateProvider\n config={mergedConfig}\n hooks={hooks}\n cookieName={cookieName}\n >\n {children}\n </AuthStateProvider>\n </QueryClientProvider>\n );\n}\n\ntype AuthStateProviderProps = {\n config: AuthClientConfig;\n hooks: OpenApiHooks;\n cookieName: string;\n children: ReactNode;\n};\n\nfunction AuthStateProvider({\n config,\n hooks,\n cookieName,\n children,\n}: AuthStateProviderProps) {\n // Manual override for sign-out / sign-in\n const [override, setOverride] = useState<AuthState | null>(null);\n\n // Always fetch session - cookie is httpOnly, can't check client-side\n // Server will read the cookie and return user/session if valid\n const {\n data: sessionData,\n isLoading,\n isFetched,\n error: sessionError,\n refetch,\n } = hooks.useQuery(\n 'get',\n '/session',\n {},\n {\n enabled: !(override || isServer()),\n refetchOnMount: false,\n refetchOnWindowFocus: false,\n refetchOnReconnect: false,\n retry: false,\n gcTime: 0,\n staleTime: 0,\n },\n );\n\n // Derive state directly - no useEffect\n const user = override?.user ?? sessionData?.user ?? null;\n const session = override?.session ?? sessionData?.session ?? null;\n const error = override?.error ?? (sessionError as Error | null);\n\n // Check error status code\n const errorStatus = (() => {\n if (!sessionError) {\n return null;\n }\n const err = sessionError as { status?: number };\n return err.status ?? null;\n })();\n\n // Check if error is a network/connection error\n const isNetworkError = (() => {\n if (!sessionError) {\n return false;\n }\n const error = sessionError as Error & { cause?: unknown; data?: unknown };\n const errorMessage =\n error.message || String(error) || JSON.stringify(error);\n // Network errors: TypeError, DOMException, or fetch failures\n if (\n error instanceof TypeError ||\n error instanceof DOMException ||\n error.name === 'TypeError' ||\n errorMessage.includes('Failed to fetch') ||\n errorMessage.includes('ERR_CONNECTION_REFUSED') ||\n errorMessage.includes('NetworkError') ||\n errorMessage.includes('Network request failed') ||\n errorMessage.includes('fetch failed')\n ) {\n return true;\n }\n // Check error cause\n if (error.cause) {\n const causeStr = String(error.cause);\n if (\n causeStr.includes('Failed to fetch') ||\n causeStr.includes('ERR_CONNECTION_REFUSED') ||\n causeStr.includes('NetworkError')\n ) {\n return true;\n }\n }\n return false;\n })();\n\n // Compute status\n // biome-ignore lint: Status determination requires multiple checks\n const status: AuthStatus = (() => {\n if (override) {\n return override.status;\n }\n if (isServer()) {\n return 'loading';\n }\n if (user && session) {\n return 'authenticated';\n }\n // Check for network errors or auth errors first - allow auth page to show\n if (isNetworkError || errorStatus === 401) {\n return 'unauthenticated';\n }\n // If we have an error but it's not a network error, still check loading state\n if (sessionError && !isNetworkError && errorStatus !== 401) {\n if (errorStatus && errorStatus >= 500) {\n return 'authenticated';\n }\n // Other errors mean unauthenticated\n if (isFetched) {\n return 'unauthenticated';\n }\n }\n if (isLoading || !isFetched) {\n return 'loading';\n }\n if (isFetched && !user && !session) {\n return 'unauthenticated';\n }\n return 'unauthenticated';\n })();\n\n const signOutMutation = hooks.useMutation('post', '/sign-out');\n const t = createTranslator(config.messages || {});\n\n const setAuth = (auth: AuthResponse) => {\n setOverride({\n user: auth.user,\n session: auth.session,\n status: 'authenticated',\n error: null,\n });\n };\n\n const clearAuth = () => {\n setOverride({\n user: null,\n session: null,\n status: 'unauthenticated',\n error: null,\n });\n };\n\n const refresh = async () => {\n setOverride(null);\n await refetch();\n };\n\n const signOut = async () => {\n try {\n await signOutMutation.mutateAsync({});\n } finally {\n clearAuth();\n }\n };\n\n return (\n <ConfigContext.Provider value={{ config, cookieName, t }}>\n <ApiContext.Provider value={{ hooks, setAuth, clearAuth, refresh }}>\n <SessionContext.Provider\n value={{\n user,\n session,\n status,\n error,\n isLoading: status === 'loading',\n isAuthenticated: status === 'authenticated',\n refresh,\n signOut,\n }}\n >\n {children}\n </SessionContext.Provider>\n </ApiContext.Provider>\n </ConfigContext.Provider>\n );\n}\n","type Messages = Record<string, unknown>;\n\nexport function createTranslator(messages: Messages, namespace?: string) {\n return (key: string, params?: Record<string, string | number>): string => {\n const fullKey = namespace ? `${namespace}.${key}` : key;\n const keys = fullKey.split('.');\n\n let value: unknown = messages;\n for (const k of keys) {\n if (value && typeof value === 'object' && value !== null) {\n value = (value as Record<string, unknown>)[k];\n } else {\n return fullKey;\n }\n }\n\n if (typeof value !== 'string') {\n return fullKey;\n }\n\n // Simple parameter replacement\n if (params) {\n return value.replace(/\\{(\\w+)\\}/g, (_, param) =>\n String(params[param] ?? `{${param}}`),\n );\n }\n\n return value;\n };\n}\n","import type { AuthClientConfig } from '../types';\n\nconst isProduction =\n typeof process !== 'undefined' && process.env.NODE_ENV === 'production';\n\nexport const getSessionCookieName = (config: AuthClientConfig): string => {\n const prefix = config.cookiePrefix || '';\n const baseName = 'session_token';\n if (prefix) {\n return `${prefix}_${baseName}`;\n }\n return isProduction ? '__Host-session_token' : baseName;\n};\n","'use client';\n\nimport { zodResolver } from '@hookform/resolvers/zod';\nimport { Button, Input, Label, Spinner } from '@mesob/ui/components';\nimport { IconEye, IconEyeOff } from '@tabler/icons-react';\nimport { useEffect, useState } from 'react';\nimport { useForm } from 'react-hook-form';\nimport { toast } from 'sonner';\nimport { z } from 'zod';\nimport { useApi, useSession } from '../../provider';\n\nconst emailPasswordSchema = z.object({\n email: z.string().email('Invalid email address'),\n password: z\n .string()\n .min(8, 'Password must be at least 8 characters')\n .max(128, 'Password too long'),\n});\n\ntype EmailPasswordFormData = z.infer<typeof emailPasswordSchema>;\n\ntype AuthErrorLike = {\n code?: string;\n message?: string;\n name?: string;\n};\n\nfunction isAuthError(error: unknown): error is AuthErrorLike {\n return (\n typeof error === 'object' &&\n error !== null &&\n ('code' in error || 'message' in error || 'name' in error)\n );\n}\n\nfunction getErrorCode(error: AuthErrorLike): string | undefined {\n if (error.code) {\n return error.code;\n }\n if (error.message) {\n const upperMessage = error.message.toUpperCase().trim();\n const validCodes = [\n 'USER_NOT_FOUND',\n 'USER_EXISTS',\n 'INVALID_PASSWORD',\n 'VERIFICATION_EXPIRED',\n 'VERIFICATION_MISMATCH',\n 'VERIFICATION_NOT_FOUND',\n 'TOO_MANY_ATTEMPTS',\n 'UNAUTHORIZED',\n ];\n if (validCodes.includes(upperMessage)) {\n return upperMessage;\n }\n }\n return undefined;\n}\n\nfunction getErrorMessage(error: unknown): string {\n if (isAuthError(error)) {\n const errorCode = getErrorCode(error);\n switch (errorCode) {\n case 'USER_EXISTS':\n return 'This email is already taken. Please use a different email.';\n case 'VERIFICATION_EXPIRED':\n return 'Verification code has expired. Please request a new one.';\n case 'VERIFICATION_MISMATCH':\n return 'Invalid verification code. Please try again.';\n case 'VERIFICATION_NOT_FOUND':\n return 'Verification not found. Please request a new code.';\n default:\n return error.message || 'An error occurred. Please try again.';\n }\n }\n if (error instanceof Error) {\n return error.message;\n }\n return 'An error occurred. Please try again.';\n}\n\ninterface RequestChangeEmailFormProps {\n onSuccess: (verificationId: string, email: string) => void;\n onCancel: () => void;\n buttonText: string;\n}\n\nexport function RequestChangeEmailForm({\n onSuccess,\n onCancel,\n buttonText,\n}: RequestChangeEmailFormProps) {\n const { user } = useSession();\n const { hooks } = useApi();\n const [isSubmitting, setIsSubmitting] = useState(false);\n const [isChecking, setIsChecking] = useState(true);\n const [showPassword, setShowPassword] = useState(false);\n\n const getPendingAccountChangeQuery = hooks.useQuery(\n 'get',\n '/account-change/pending',\n {},\n { enabled: false },\n );\n const verifyPasswordMutation = hooks.useMutation('post', '/password/verify');\n const checkUserMutation = hooks.useMutation('post', '/check-account');\n const requestEmailVerificationMutation = hooks.useMutation(\n 'post',\n '/email/verification/request',\n );\n\n const emailPasswordForm = useForm<EmailPasswordFormData>({\n resolver: zodResolver(emailPasswordSchema),\n defaultValues: {\n email: '',\n password: '',\n },\n });\n\n const {\n register,\n handleSubmit,\n getValues,\n setValue,\n formState: { errors },\n } = emailPasswordForm;\n\n useEffect(() => {\n let active = true;\n const run = async () => {\n try {\n const data = await getPendingAccountChangeQuery.refetch();\n if (!active) {\n return;\n }\n const accountChange = data.data?.accountChange;\n const verificationId = data.data?.verificationId;\n if (accountChange?.changeType !== 'email') {\n setIsChecking(false);\n return;\n }\n if (!accountChange.newEmail) {\n setIsChecking(false);\n return;\n }\n if (getValues('email')) {\n setIsChecking(false);\n return;\n }\n setValue('email', accountChange.newEmail, { shouldValidate: true });\n\n if (verificationId) {\n toast.message('Resuming verification…');\n onSuccess(verificationId, accountChange.newEmail);\n return;\n }\n\n setIsChecking(false);\n } catch {\n setIsChecking(false);\n }\n };\n run().catch(() => undefined);\n return () => {\n active = false;\n };\n }, [getPendingAccountChangeQuery.refetch, getValues, onSuccess, setValue]);\n\n const onEmailPasswordSubmit = async (data: EmailPasswordFormData) => {\n if (!user) {\n toast.error('User not found');\n return;\n }\n\n try {\n setIsSubmitting(true);\n\n // Verify password first\n await verifyPasswordMutation.mutateAsync({\n body: { password: data.password },\n });\n\n // Check if email exists\n const checkResult = await checkUserMutation.mutateAsync({\n body: { identifier: data.email },\n });\n if (checkResult.data?.exists) {\n // Check if it belongs to current user\n if (user?.email?.toLowerCase() === data.email.toLowerCase()) {\n toast.error('This is already your current email address.');\n return;\n }\n toast.error(\n 'This email is already taken. Please use a different email.',\n );\n return;\n }\n\n // Request verification\n const verification = await requestEmailVerificationMutation.mutateAsync({\n body: { email: data.email },\n });\n\n toast.success('Verification code sent to your email');\n onSuccess(verification.data?.verificationId ?? '', data.email);\n } catch (error) {\n const errorMessage = getErrorMessage(error);\n if (isAuthError(error)) {\n const errorCode = getErrorCode(error);\n if (\n errorCode === 'INVALID_PASSWORD' ||\n errorCode === 'USER_NOT_FOUND'\n ) {\n toast.error('Incorrect password. Please try again.');\n return;\n }\n }\n toast.error(errorMessage);\n } finally {\n setIsSubmitting(false);\n }\n };\n\n const isLoading = isSubmitting || isChecking;\n\n return (\n <form\n onSubmit={handleSubmit(onEmailPasswordSubmit)}\n className=\"p-4 space-y-4 border-t\"\n >\n <div className=\"space-y-4 w-full md:w-1/2\">\n <div className=\"space-y-2\">\n <Label htmlFor=\"email\">New Email Address</Label>\n <Input\n id=\"email\"\n type=\"email\"\n placeholder=\"Enter your new email\"\n {...register('email')}\n disabled={isLoading}\n />\n {errors.email && (\n <p className=\"text-sm text-destructive\">{errors.email.message}</p>\n )}\n </div>\n <div className=\"space-y-2\">\n <Label htmlFor=\"password\">Password</Label>\n <div className=\"relative\">\n <Input\n id=\"password\"\n type={showPassword ? 'text' : 'password'}\n autoComplete=\"current-password\"\n placeholder=\"Enter your password\"\n {...register('password')}\n disabled={isLoading}\n />\n <button\n type=\"button\"\n onClick={() => setShowPassword(!showPassword)}\n className=\"absolute right-3 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground\"\n disabled={isLoading}\n >\n {showPassword ? (\n <IconEyeOff className=\"h-4 w-4\" />\n ) : (\n <IconEye className=\"h-4 w-4\" />\n )}\n </button>\n </div>\n {errors.password && (\n <p className=\"text-sm text-destructive\">\n {errors.password.message}\n </p>\n )}\n </div>\n </div>\n\n <div className=\"flex justify-end gap-2\">\n <Button\n type=\"button\"\n variant=\"outline\"\n onClick={onCancel}\n disabled={isLoading}\n >\n Cancel\n </Button>\n <Button type=\"submit\" disabled={isLoading}>\n {isLoading && <Spinner className=\"mr-2 h-4 w-4\" />}\n {isChecking ? 'Checking…' : buttonText}\n </Button>\n </div>\n </form>\n );\n}\n","'use client';\n\nimport { useState } from 'react';\nimport { toast } from 'sonner';\nimport { useApi, useSession } from '../../provider';\nimport { OtpVerificationModal } from './otp-verification-modal';\n\ntype AuthErrorLike = {\n code?: string;\n message?: string;\n name?: string;\n};\n\nfunction isAuthError(error: unknown): error is AuthErrorLike {\n return (\n typeof error === 'object' &&\n error !== null &&\n ('code' in error || 'message' in error || 'name' in error)\n );\n}\n\nfunction getErrorCode(error: AuthErrorLike): string | undefined {\n if (error.code) {\n return error.code;\n }\n if (error.message) {\n const upperMessage = error.message.toUpperCase().trim();\n const validCodes = [\n 'USER_NOT_FOUND',\n 'USER_EXISTS',\n 'INVALID_PASSWORD',\n 'VERIFICATION_EXPIRED',\n 'VERIFICATION_MISMATCH',\n 'VERIFICATION_NOT_FOUND',\n 'TOO_MANY_ATTEMPTS',\n 'UNAUTHORIZED',\n ];\n if (validCodes.includes(upperMessage)) {\n return upperMessage;\n }\n }\n return undefined;\n}\n\nfunction getErrorMessage(error: unknown): string {\n if (isAuthError(error)) {\n const errorCode = getErrorCode(error);\n switch (errorCode) {\n case 'USER_EXISTS':\n return 'This email is already taken. Please use a different email.';\n case 'VERIFICATION_EXPIRED':\n return 'Verification code has expired. Please request a new one.';\n case 'VERIFICATION_MISMATCH':\n return 'Invalid verification code. Please try again.';\n case 'VERIFICATION_NOT_FOUND':\n return 'Verification not found. Please request a new code.';\n default:\n return error.message || 'An error occurred. Please try again.';\n }\n }\n if (error instanceof Error) {\n return error.message;\n }\n return 'An error occurred. Please try again.';\n}\n\ntype VerifyChangeEmailFormProps = {\n email: string;\n verificationId: string | null;\n onSuccess: () => void;\n onCancel: () => void;\n};\n\nexport function VerifyChangeEmailForm({\n email,\n verificationId,\n onSuccess,\n onCancel,\n}: VerifyChangeEmailFormProps) {\n const { refresh } = useSession();\n const { hooks } = useApi();\n const [isSubmitting, setIsSubmitting] = useState(false);\n const [currentVerificationId, setCurrentVerificationId] =\n useState(verificationId);\n\n const verifyEmailMutation = hooks.useMutation(\n 'post',\n '/email/verification/confirm',\n );\n const updateEmailMutation = hooks.useMutation('put', '/profile/email');\n const requestEmailVerificationMutation = hooks.useMutation(\n 'post',\n '/email/verification/request',\n );\n\n const onOtpSubmit = async (code: string) => {\n if (!currentVerificationId) {\n toast.error('Verification not found. Please request a new code.');\n return;\n }\n try {\n setIsSubmitting(true);\n\n // Verify email\n await verifyEmailMutation.mutateAsync({\n body: {\n verificationId: currentVerificationId,\n code,\n },\n });\n\n // Update email via auth client\n await updateEmailMutation.mutateAsync({\n body: { email },\n });\n\n toast.success('Email updated successfully');\n await refresh();\n onSuccess();\n } catch (error) {\n const errorMessage = getErrorMessage(error);\n toast.error(errorMessage);\n } finally {\n setIsSubmitting(false);\n }\n };\n\n if (!currentVerificationId) {\n toast.error('Verification not found. Please request a new code.');\n return null;\n }\n\n return (\n <OtpVerificationModal\n open\n title=\"Verify email\"\n description={`Enter the verification code sent to ${email}`}\n verificationId={currentVerificationId}\n isLoading={isSubmitting}\n onSubmit={onOtpSubmit}\n onResend={async () => {\n try {\n setIsSubmitting(true);\n const next = await requestEmailVerificationMutation.mutateAsync({\n body: { email },\n });\n setCurrentVerificationId(next.data?.verificationId ?? null);\n toast.success('Verification code resent');\n } catch (error) {\n toast.error(getErrorMessage(error));\n } finally {\n setIsSubmitting(false);\n }\n }}\n onCancel={onCancel}\n />\n );\n}\n","'use client';\n\nimport {\n Dialog,\n DialogContent,\n DialogDescription,\n DialogHeader,\n DialogTitle,\n} from '@mesob/ui/components';\nimport { VerificationForm } from '../auth/verification-form';\n\ntype OtpVerificationModalProps = {\n open: boolean;\n title: string;\n description?: string;\n verificationId: string;\n isLoading?: boolean;\n onSubmit: (code: string) => Promise<void> | void;\n onResend?: () => Promise<void> | void;\n onCancel?: () => void;\n};\n\nexport function OtpVerificationModal({\n open,\n title,\n description,\n verificationId,\n isLoading,\n onSubmit,\n onResend,\n onCancel,\n}: OtpVerificationModalProps) {\n return (\n <Dialog\n open={open}\n onOpenChange={(nextOpen: boolean) => {\n if (!nextOpen) {\n onCancel?.();\n }\n }}\n >\n <DialogContent>\n <DialogHeader>\n <DialogTitle>{title}</DialogTitle>\n {description && <DialogDescription>{description}</DialogDescription>}\n </DialogHeader>\n\n <VerificationForm\n verificationId={verificationId}\n isLoading={isLoading}\n onSubmit={async ({ code }: { code: string }) => onSubmit(code)}\n onResend={onResend ?? (() => undefined)}\n />\n </DialogContent>\n </Dialog>\n );\n}\n","'use client';\n\nimport { zodResolver } from '@hookform/resolvers/zod';\nimport {\n Button,\n Form,\n FormControl,\n FormField,\n FormItem,\n FormLabel,\n FormMessage,\n InputOTP,\n InputOTPGroup,\n InputOTPSlot,\n Spinner,\n} from '@mesob/ui/components';\nimport { useForm } from 'react-hook-form';\nimport { z } from 'zod';\nimport { useTranslator } from '../../hooks/use-translator';\nimport type { AuthErrorContent } from '../../utils/handle-error';\nimport { Countdown } from './countdown';\n\ntype VerificationFormValues = {\n code: string;\n};\n\ntype VerificationFormProps = {\n verificationId: string;\n onSubmit: (values: VerificationFormValues) => Promise<void> | void;\n onResend: () => Promise<void> | void;\n isLoading?: boolean;\n error?: AuthErrorContent | string | null;\n};\n\nconst verificationSchema = (t: (key: string) => string) =>\n z.object({\n code: z.string().length(6, t('form.codeLength')),\n });\n\nexport const VerificationForm = ({\n onSubmit,\n onResend,\n isLoading = false,\n}: VerificationFormProps) => {\n const t = useTranslator('Auth.verification');\n const form = useForm<VerificationFormValues>({\n resolver: zodResolver(verificationSchema(t)),\n defaultValues: {\n code: '',\n },\n });\n\n const handleSubmit = form.handleSubmit(async (values) => {\n await onSubmit(values);\n });\n\n return (\n <Form {...form}>\n <form\n id=\"verification-form\"\n onSubmit={handleSubmit}\n className=\"space-y-4\"\n >\n <FormField\n control={form.control}\n name=\"code\"\n render={({ field }) => (\n <FormItem>\n <div className=\"flex justify-center\">\n <FormLabel>{t('form.codeLabel')}</FormLabel>\n </div>\n <FormControl>\n <InputOTP\n maxLength={6}\n required\n value={field.value ?? ''}\n onChange={field.onChange}\n onBlur={field.onBlur}\n containerClassName=\"gap-4 justify-center mb-2 flex items-center\"\n >\n <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\">\n <InputOTPSlot className=\"h-12\" index={0} />\n <InputOTPSlot className=\"h-12\" index={1} />\n <InputOTPSlot className=\"h-12\" index={2} />\n <InputOTPSlot className=\"h-12\" index={3} />\n <InputOTPSlot className=\"h-12\" index={4} />\n <InputOTPSlot className=\"h-12\" index={5} />\n </InputOTPGroup>\n </InputOTP>\n </FormControl>\n <FormMessage />\n </FormItem>\n )}\n />\n <div className=\"flex justify-between items-center\">\n <Countdown onResend={onResend} resending={isLoading} />\n <Button\n type=\"submit\"\n form=\"verification-form\"\n disabled={isLoading || form.watch('code').length !== 6}\n >\n {isLoading && <Spinner />}\n {t('form.confirm')}\n </Button>\n </div>\n </form>\n </Form>\n );\n};\n","import { useMesob } from '@mesob/ui/providers';\nimport { createTranslator } from '../lib/translations';\nimport { useConfig } from '../provider';\n\nexport function useTranslator(namespace?: string) {\n const mesob = useMesob();\n const { config } = useConfig();\n\n if (mesob?.t) {\n return (key: string, params?: Record<string, string | number>): string => {\n const fullKey = namespace ? `${namespace}.${key}` : key;\n return mesob.t?.(fullKey, params) ?? fullKey;\n };\n }\n\n return createTranslator(config.messages || {}, namespace);\n}\n","'use client';\n\nimport { Button, Spinner } from '@mesob/ui/components';\nimport { useEffect, useState } from 'react';\nimport { useTranslator } from '../../hooks/use-translator';\n\ntype CountdownProps = {\n initialSeconds?: number;\n onResend: () => Promise<void> | void;\n resending?: boolean;\n};\n\nexport const Countdown = ({\n initialSeconds = 60,\n onResend,\n resending = false,\n}: CountdownProps) => {\n const t = useTranslator('Common');\n const [seconds, setSeconds] = useState(initialSeconds);\n const [isResending, setIsResending] = useState(false);\n\n useEffect(() => {\n if (seconds <= 0) {\n return;\n }\n\n const timer = setInterval(() => {\n setSeconds((prev) => {\n if (prev <= 1) {\n clearInterval(timer);\n return 0;\n }\n return prev - 1;\n });\n }, 1000);\n\n return () => clearInterval(timer);\n }, [seconds]);\n\n const handleResend = async () => {\n setIsResending(true);\n try {\n await onResend();\n setSeconds(initialSeconds);\n } catch (_error) {\n // Error handling is done by parent\n } finally {\n setIsResending(false);\n }\n };\n\n if (seconds > 0) {\n return (\n <Button variant=\"ghost\" disabled>\n {t('resendIn', { seconds })}\n </Button>\n );\n }\n\n return (\n <Button\n variant=\"ghost\"\n onClick={handleResend}\n disabled={isResending || resending}\n >\n {isResending || (resending && <Spinner />)}\n {t('resend')}\n </Button>\n );\n};\n"],"mappings":";;;AAEA;AAAA,EACE,UAAAA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,uBAAuB;AAChC,SAAS,YAAAC,iBAAgB;;;ACPzB,SAAS,aAAa,2BAA2B;AACjD,SAAS,iBAAiB;AAC1B,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,UAAU;AAAA;AAAA,IACZ,IAEA,gBAAAA;AAAA,MAAC;AAAA;AAAA,QACC,WAAW;AAAA,QACX,UAAU;AAAA,QACV,YAAY;AAAA;AAAA,IACd,GAEJ;AAAA,KACF,GACF;AAEJ;","names":["Button","useState","useState","jsx","useState","useState","toast","zodResolver","Button","Spinner","useForm","z","Button","Spinner","useEffect","useState","jsx","jsxs","useState","useEffect","Button","Spinner","jsx","jsxs","z","useForm","zodResolver","Button","Spinner","jsx","jsxs","jsx","isAuthError","getErrorCode","getErrorMessage","useState","toast","jsx","jsxs","useState","Button"]}
1
+ {"version":3,"sources":["../../../src/components/profile/change-email-form.tsx","../../../src/provider.tsx","../../../src/lib/translations.ts","../../../src/utils/cookie.ts","../../../src/components/profile/request-change-email-form.tsx","../../../src/components/profile/verify-change-email-form.tsx","../../../src/components/profile/otp-verification-modal.tsx","../../../src/components/auth/verification-form.tsx","../../../src/hooks/use-translator.ts","../../../src/components/auth/countdown.tsx"],"sourcesContent":["'use client';\n\nimport {\n Button,\n Collapsible,\n CollapsibleContent,\n CollapsibleTrigger,\n} from '@mesob/ui/components';\nimport { IconChevronDown } from '@tabler/icons-react';\nimport { useState } from 'react';\nimport { useSession } from '../../provider';\nimport { RequestChangeEmailForm } from './request-change-email-form';\nimport { VerifyChangeEmailForm } from './verify-change-email-form';\n\nexport function ChangeEmailForm() {\n const { user } = useSession();\n const [isOpen, setIsOpen] = useState(false);\n const [showOtp, setShowOtp] = useState(false);\n const [verificationId, setVerificationId] = useState<string | null>(null);\n const [newEmail, setNewEmail] = useState<string>('');\n\n const resetForms = () => {\n setShowOtp(false);\n setVerificationId(null);\n setNewEmail('');\n };\n\n const handleRequestSuccess = (id: string, email: string) => {\n setVerificationId(id);\n setNewEmail(email);\n setShowOtp(true);\n };\n\n const handleVerifySuccess = () => {\n resetForms();\n setIsOpen(false);\n };\n\n const handleCancel = () => {\n resetForms();\n setIsOpen(false);\n };\n\n const title = user?.email ? 'Change Email' : 'Add Email';\n const description = user?.email\n ? 'Update your email address'\n : 'Add an email address to your account';\n return (\n <Collapsible open={isOpen} onOpenChange={setIsOpen}>\n <div className=\"border rounded-lg\">\n <CollapsibleTrigger\n render={\n <Button\n variant=\"ghost\"\n className=\"w-full justify-between p-4 h-auto\"\n />\n }\n >\n <div className=\"flex flex-col items-start\">\n <span className=\"font-medium\">{title}</span>\n <span className=\"text-sm text-muted-foreground\">{description}</span>\n </div>\n <IconChevronDown\n className={`h-4 w-4 transition-transform ${\n isOpen ? 'rotate-180' : ''\n }`}\n />\n </CollapsibleTrigger>\n\n <CollapsibleContent>\n {showOtp ? (\n <VerifyChangeEmailForm\n email={newEmail}\n verificationId={verificationId}\n onSuccess={handleVerifySuccess}\n onCancel={handleCancel}\n />\n ) : (\n <RequestChangeEmailForm\n onSuccess={handleRequestSuccess}\n onCancel={handleCancel}\n buttonText={title}\n />\n )}\n </CollapsibleContent>\n </div>\n </Collapsible>\n );\n}\n","'use client';\n\nimport { QueryClient, QueryClientProvider } from '@tanstack/react-query';\nimport { deepmerge } from 'deepmerge-ts';\nimport createFetchClient from 'openapi-fetch';\nimport createClient from 'openapi-react-query';\nimport type { ReactNode } from 'react';\nimport { createContext, useContext, useMemo, useState } from 'react';\nimport type { paths } from './data/openapi';\nimport { createTranslator } from './lib/translations';\nimport {\n type AuthClientConfig,\n type AuthResponse,\n defaultAuthClientConfig,\n type Session,\n type User,\n} from './types';\nimport { getSessionCookieName } from './utils/cookie';\nimport { createCustomFetch } from './utils/custom-fetch';\n\n// biome-ignore lint/suspicious/noExplicitAny: OpenAPI hooks type\ntype OpenApiHooks = any;\n\n// --- Utility: Check if running on server ---\nfunction isServer(): boolean {\n return typeof document === 'undefined';\n}\n\n/**\n * @deprecated Cookie is httpOnly and cannot be read client-side.\n * Use `useSession().isAuthenticated` instead.\n * This function always returns false on client.\n */\nexport function hasAuthCookie(_cookieName: string): boolean {\n // Cookie is httpOnly, can't check client-side\n // Always return false - use useSession() for auth status\n return false;\n}\n\n// --- Types ---\nexport type AuthStatus = 'loading' | 'authenticated' | 'unauthenticated';\n\ntype AuthState = {\n user: User | null;\n session: Session | null;\n status: AuthStatus;\n error: Error | null;\n};\n\ntype SessionContextValue = AuthState & {\n isLoading: boolean;\n isAuthenticated: boolean;\n refresh: () => Promise<void>;\n signOut: () => Promise<void>;\n};\n\ntype ApiContextValue = {\n hooks: OpenApiHooks;\n setAuth: (auth: AuthResponse) => void;\n clearAuth: () => void;\n refresh: () => Promise<void>;\n};\n\ntype ConfigContextValue = {\n config: AuthClientConfig;\n cookieName: string;\n t: (key: string, params?: Record<string, string | number>) => string;\n};\n\nconst SessionContext = createContext<SessionContextValue | null>(null);\nconst ApiContext = createContext<ApiContextValue | null>(null);\nconst ConfigContext = createContext<ConfigContextValue | null>(null);\n\nconst queryClient = new QueryClient({\n defaultOptions: {\n queries: {\n refetchOnWindowFocus: false,\n },\n },\n});\n\n// --- Hooks ---\n\n/**\n * Get session state including user, session, and auth status.\n * - `status`: 'loading' | 'authenticated' | 'unauthenticated'\n * - `isLoading`: true while fetching session\n * - `isAuthenticated`: true if user and session exist\n */\nexport function useSession(): SessionContextValue {\n const context = useContext(SessionContext);\n if (!context) {\n throw new Error('useSession must be used within MesobAuthProvider');\n }\n return context;\n}\n\nexport function useApi(): ApiContextValue {\n const context = useContext(ApiContext);\n if (!context) {\n throw new Error('useApi must be used within MesobAuthProvider');\n }\n return context;\n}\n\nexport function useConfig(): ConfigContextValue {\n const context = useContext(ConfigContext);\n if (!context) {\n throw new Error('useConfig must be used within MesobAuthProvider');\n }\n return context;\n}\n\n/**\n * @deprecated Cookie is httpOnly, can't be checked client-side.\n * Use `useSession().isAuthenticated` instead.\n */\nexport function useHasAuthCookie(): boolean {\n const { status } = useSession();\n return status === 'authenticated' || status === 'loading';\n}\n\n// --- Provider ---\n\ntype MesobAuthProviderProps = {\n config: AuthClientConfig;\n children: ReactNode;\n};\n\nexport function MesobAuthProvider({\n config,\n children,\n}: MesobAuthProviderProps) {\n const mergedConfig = useMemo(\n () =>\n deepmerge(\n { ...defaultAuthClientConfig } as Partial<AuthClientConfig>,\n config,\n ) as AuthClientConfig,\n [config],\n );\n\n const api = useMemo(\n () =>\n createFetchClient<paths>({\n baseUrl: mergedConfig.baseURL,\n fetch: createCustomFetch(mergedConfig),\n }),\n [mergedConfig],\n );\n\n const hooks = useMemo(() => createClient(api), [api]);\n const cookieName = useMemo(\n () => getSessionCookieName(mergedConfig),\n [mergedConfig],\n );\n\n return (\n <QueryClientProvider client={queryClient}>\n <AuthStateProvider\n config={mergedConfig}\n hooks={hooks}\n cookieName={cookieName}\n >\n {children}\n </AuthStateProvider>\n </QueryClientProvider>\n );\n}\n\ntype AuthStateProviderProps = {\n config: AuthClientConfig;\n hooks: OpenApiHooks;\n cookieName: string;\n children: ReactNode;\n};\n\nfunction AuthStateProvider({\n config,\n hooks,\n cookieName,\n children,\n}: AuthStateProviderProps) {\n // Manual override for sign-out / sign-in\n const [override, setOverride] = useState<AuthState | null>(null);\n\n // Always fetch session - cookie is httpOnly, can't check client-side\n // Server will read the cookie and return user/session if valid\n const {\n data: sessionData,\n isLoading,\n isFetched,\n error: sessionError,\n refetch,\n } = hooks.useQuery(\n 'get',\n '/session',\n {},\n {\n enabled: !(override || isServer()),\n refetchOnMount: false,\n refetchOnWindowFocus: false,\n refetchOnReconnect: false,\n retry: false,\n gcTime: 0,\n staleTime: 0,\n },\n );\n\n // Derive state directly - no useEffect\n const user = override?.user ?? sessionData?.user ?? null;\n const session = override?.session ?? sessionData?.session ?? null;\n const error = override?.error ?? (sessionError as Error | null);\n\n // Check error status code\n const errorStatus = (() => {\n if (!sessionError) {\n return null;\n }\n const err = sessionError as { status?: number };\n return err.status ?? null;\n })();\n\n // Check if error is a network/connection error\n const isNetworkError = (() => {\n if (!sessionError) {\n return false;\n }\n const error = sessionError as Error & { cause?: unknown; data?: unknown };\n const errorMessage =\n error.message || String(error) || JSON.stringify(error);\n // Network errors: TypeError, DOMException, or fetch failures\n if (\n error instanceof TypeError ||\n error instanceof DOMException ||\n error.name === 'TypeError' ||\n errorMessage.includes('Failed to fetch') ||\n errorMessage.includes('ERR_CONNECTION_REFUSED') ||\n errorMessage.includes('NetworkError') ||\n errorMessage.includes('Network request failed') ||\n errorMessage.includes('fetch failed')\n ) {\n return true;\n }\n // Check error cause\n if (error.cause) {\n const causeStr = String(error.cause);\n if (\n causeStr.includes('Failed to fetch') ||\n causeStr.includes('ERR_CONNECTION_REFUSED') ||\n causeStr.includes('NetworkError')\n ) {\n return true;\n }\n }\n return false;\n })();\n\n // Compute status\n // biome-ignore lint: Status determination requires multiple checks\n const status: AuthStatus = (() => {\n if (override) {\n return override.status;\n }\n if (isServer()) {\n return 'loading';\n }\n if (user && session) {\n return 'authenticated';\n }\n // Check for network errors or auth errors first - allow auth page to show\n if (isNetworkError || errorStatus === 401) {\n return 'unauthenticated';\n }\n // If we have an error but it's not a network error, still check loading state\n if (sessionError && !isNetworkError && errorStatus !== 401) {\n if (errorStatus && errorStatus >= 500) {\n return 'authenticated';\n }\n // Other errors mean unauthenticated\n if (isFetched) {\n return 'unauthenticated';\n }\n }\n if (isLoading || !isFetched) {\n return 'loading';\n }\n if (isFetched && !user && !session) {\n return 'unauthenticated';\n }\n return 'unauthenticated';\n })();\n\n const signOutMutation = hooks.useMutation('post', '/sign-out');\n const t = createTranslator(config.messages || {});\n\n const setAuth = (auth: AuthResponse) => {\n setOverride({\n user: auth.user,\n session: auth.session,\n status: 'authenticated',\n error: null,\n });\n };\n\n const clearAuth = () => {\n setOverride({\n user: null,\n session: null,\n status: 'unauthenticated',\n error: null,\n });\n };\n\n const refresh = async () => {\n setOverride(null);\n await refetch();\n };\n\n const signOut = async () => {\n try {\n await signOutMutation.mutateAsync({});\n } finally {\n clearAuth();\n }\n };\n\n return (\n <ConfigContext.Provider value={{ config, cookieName, t }}>\n <ApiContext.Provider value={{ hooks, setAuth, clearAuth, refresh }}>\n <SessionContext.Provider\n value={{\n user,\n session,\n status,\n error,\n isLoading: status === 'loading',\n isAuthenticated: status === 'authenticated',\n refresh,\n signOut,\n }}\n >\n {children}\n </SessionContext.Provider>\n </ApiContext.Provider>\n </ConfigContext.Provider>\n );\n}\n","type Messages = Record<string, unknown>;\n\nexport function createTranslator(messages: Messages, namespace?: string) {\n return (key: string, params?: Record<string, string | number>): string => {\n const fullKey = namespace ? `${namespace}.${key}` : key;\n const keys = fullKey.split('.');\n\n let value: unknown = messages;\n for (const k of keys) {\n if (value && typeof value === 'object' && value !== null) {\n value = (value as Record<string, unknown>)[k];\n } else {\n return fullKey;\n }\n }\n\n if (typeof value !== 'string') {\n return fullKey;\n }\n\n // Simple parameter replacement\n if (params) {\n return value.replace(/\\{(\\w+)\\}/g, (_, param) =>\n String(params[param] ?? `{${param}}`),\n );\n }\n\n return value;\n };\n}\n","import type { AuthClientConfig } from '../types';\n\nconst isProduction =\n typeof process !== 'undefined' && process.env.NODE_ENV === 'production';\n\nexport const getSessionCookieName = (config: AuthClientConfig): string => {\n const prefix = config.cookiePrefix || '';\n const baseName = 'session_token';\n if (prefix) {\n return `${prefix}_${baseName}`;\n }\n return isProduction ? '__Host-session_token' : baseName;\n};\n","'use client';\n\nimport { zodResolver } from '@hookform/resolvers/zod';\nimport { Button, Input, Label, Spinner } from '@mesob/ui/components';\nimport { IconEye, IconEyeOff } from '@tabler/icons-react';\nimport { useEffect, useState } from 'react';\nimport { useForm } from 'react-hook-form';\nimport { toast } from 'sonner';\nimport { z } from 'zod';\nimport { useApi, useSession } from '../../provider';\n\nconst emailPasswordSchema = z.object({\n email: z.string().email('Invalid email address'),\n password: z\n .string()\n .min(8, 'Password must be at least 8 characters')\n .max(128, 'Password too long'),\n});\n\ntype EmailPasswordFormData = z.infer<typeof emailPasswordSchema>;\n\ntype AuthErrorLike = {\n code?: string;\n message?: string;\n name?: string;\n};\n\nfunction isAuthError(error: unknown): error is AuthErrorLike {\n return (\n typeof error === 'object' &&\n error !== null &&\n ('code' in error || 'message' in error || 'name' in error)\n );\n}\n\nfunction getErrorCode(error: AuthErrorLike): string | undefined {\n if (error.code) {\n return error.code;\n }\n if (error.message) {\n const upperMessage = error.message.toUpperCase().trim();\n const validCodes = [\n 'USER_NOT_FOUND',\n 'USER_EXISTS',\n 'INVALID_PASSWORD',\n 'VERIFICATION_EXPIRED',\n 'VERIFICATION_MISMATCH',\n 'VERIFICATION_NOT_FOUND',\n 'TOO_MANY_ATTEMPTS',\n 'UNAUTHORIZED',\n ];\n if (validCodes.includes(upperMessage)) {\n return upperMessage;\n }\n }\n return undefined;\n}\n\nfunction getErrorMessage(error: unknown): string {\n if (isAuthError(error)) {\n const errorCode = getErrorCode(error);\n switch (errorCode) {\n case 'USER_EXISTS':\n return 'This email is already taken. Please use a different email.';\n case 'VERIFICATION_EXPIRED':\n return 'Verification code has expired. Please request a new one.';\n case 'VERIFICATION_MISMATCH':\n return 'Invalid verification code. Please try again.';\n case 'VERIFICATION_NOT_FOUND':\n return 'Verification not found. Please request a new code.';\n default:\n return error.message || 'An error occurred. Please try again.';\n }\n }\n if (error instanceof Error) {\n return error.message;\n }\n return 'An error occurred. Please try again.';\n}\n\ninterface RequestChangeEmailFormProps {\n onSuccess: (verificationId: string, email: string) => void;\n onCancel: () => void;\n buttonText: string;\n}\n\nexport function RequestChangeEmailForm({\n onSuccess,\n onCancel,\n buttonText,\n}: RequestChangeEmailFormProps) {\n const { user } = useSession();\n const { hooks } = useApi();\n const [isSubmitting, setIsSubmitting] = useState(false);\n const [isChecking, setIsChecking] = useState(true);\n const [showPassword, setShowPassword] = useState(false);\n\n const getPendingAccountChangeQuery = hooks.useQuery(\n 'get',\n '/account-change/pending',\n {},\n { enabled: false },\n );\n const verifyPasswordMutation = hooks.useMutation('post', '/password/verify');\n const checkUserMutation = hooks.useMutation('post', '/check-account');\n const requestEmailVerificationMutation = hooks.useMutation(\n 'post',\n '/email/verification/request',\n );\n\n const emailPasswordForm = useForm<EmailPasswordFormData>({\n resolver: zodResolver(emailPasswordSchema),\n defaultValues: {\n email: '',\n password: '',\n },\n });\n\n const {\n register,\n handleSubmit,\n getValues,\n setValue,\n formState: { errors },\n } = emailPasswordForm;\n\n useEffect(() => {\n let active = true;\n const run = async () => {\n try {\n const data = await getPendingAccountChangeQuery.refetch();\n if (!active) {\n return;\n }\n const accountChange = data.data?.accountChange;\n const verificationId = data.data?.verificationId;\n if (accountChange?.changeType !== 'email') {\n setIsChecking(false);\n return;\n }\n if (!accountChange.newEmail) {\n setIsChecking(false);\n return;\n }\n if (getValues('email')) {\n setIsChecking(false);\n return;\n }\n setValue('email', accountChange.newEmail, { shouldValidate: true });\n\n if (verificationId) {\n toast.message('Resuming verification…');\n onSuccess(verificationId, accountChange.newEmail);\n return;\n }\n\n setIsChecking(false);\n } catch {\n setIsChecking(false);\n }\n };\n run().catch(() => undefined);\n return () => {\n active = false;\n };\n }, [getPendingAccountChangeQuery.refetch, getValues, onSuccess, setValue]);\n\n const onEmailPasswordSubmit = async (data: EmailPasswordFormData) => {\n if (!user) {\n toast.error('User not found');\n return;\n }\n\n try {\n setIsSubmitting(true);\n\n // Verify password first\n await verifyPasswordMutation.mutateAsync({\n body: { password: data.password },\n });\n\n // Check if email exists\n const checkResult = await checkUserMutation.mutateAsync({\n body: { identifier: data.email },\n });\n if (checkResult.data?.exists) {\n // Check if it belongs to current user\n if (user?.email?.toLowerCase() === data.email.toLowerCase()) {\n toast.error('This is already your current email address.');\n return;\n }\n toast.error(\n 'This email is already taken. Please use a different email.',\n );\n return;\n }\n\n // Request verification\n const verification = await requestEmailVerificationMutation.mutateAsync({\n body: { email: data.email },\n });\n\n toast.success('Verification code sent to your email');\n onSuccess(verification.data?.verificationId ?? '', data.email);\n } catch (error) {\n const errorMessage = getErrorMessage(error);\n if (isAuthError(error)) {\n const errorCode = getErrorCode(error);\n if (\n errorCode === 'INVALID_PASSWORD' ||\n errorCode === 'USER_NOT_FOUND'\n ) {\n toast.error('Incorrect password. Please try again.');\n return;\n }\n }\n toast.error(errorMessage);\n } finally {\n setIsSubmitting(false);\n }\n };\n\n const isLoading = isSubmitting || isChecking;\n\n return (\n <form\n onSubmit={handleSubmit(onEmailPasswordSubmit)}\n className=\"p-4 space-y-4 border-t\"\n >\n <div className=\"space-y-4 w-full md:w-1/2\">\n <div className=\"space-y-2\">\n <Label htmlFor=\"email\">New Email Address</Label>\n <Input\n id=\"email\"\n type=\"email\"\n placeholder=\"Enter your new email\"\n {...register('email')}\n disabled={isLoading}\n />\n {errors.email && (\n <p className=\"text-sm text-destructive\">{errors.email.message}</p>\n )}\n </div>\n <div className=\"space-y-2\">\n <Label htmlFor=\"password\">Password</Label>\n <div className=\"relative\">\n <Input\n id=\"password\"\n type={showPassword ? 'text' : 'password'}\n autoComplete=\"current-password\"\n placeholder=\"Enter your password\"\n {...register('password')}\n disabled={isLoading}\n />\n <button\n type=\"button\"\n onClick={() => setShowPassword(!showPassword)}\n className=\"absolute right-3 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground\"\n disabled={isLoading}\n >\n {showPassword ? (\n <IconEyeOff className=\"h-4 w-4\" />\n ) : (\n <IconEye className=\"h-4 w-4\" />\n )}\n </button>\n </div>\n {errors.password && (\n <p className=\"text-sm text-destructive\">\n {errors.password.message}\n </p>\n )}\n </div>\n </div>\n\n <div className=\"flex justify-end gap-2\">\n <Button\n type=\"button\"\n variant=\"outline\"\n onClick={onCancel}\n disabled={isLoading}\n >\n Cancel\n </Button>\n <Button type=\"submit\" disabled={isLoading}>\n {isLoading && <Spinner className=\"mr-2 h-4 w-4\" />}\n {isChecking ? 'Checking…' : buttonText}\n </Button>\n </div>\n </form>\n );\n}\n","'use client';\n\nimport { useState } from 'react';\nimport { toast } from 'sonner';\nimport { useApi, useSession } from '../../provider';\nimport { OtpVerificationModal } from './otp-verification-modal';\n\ntype AuthErrorLike = {\n code?: string;\n message?: string;\n name?: string;\n};\n\nfunction isAuthError(error: unknown): error is AuthErrorLike {\n return (\n typeof error === 'object' &&\n error !== null &&\n ('code' in error || 'message' in error || 'name' in error)\n );\n}\n\nfunction getErrorCode(error: AuthErrorLike): string | undefined {\n if (error.code) {\n return error.code;\n }\n if (error.message) {\n const upperMessage = error.message.toUpperCase().trim();\n const validCodes = [\n 'USER_NOT_FOUND',\n 'USER_EXISTS',\n 'INVALID_PASSWORD',\n 'VERIFICATION_EXPIRED',\n 'VERIFICATION_MISMATCH',\n 'VERIFICATION_NOT_FOUND',\n 'TOO_MANY_ATTEMPTS',\n 'UNAUTHORIZED',\n ];\n if (validCodes.includes(upperMessage)) {\n return upperMessage;\n }\n }\n return undefined;\n}\n\nfunction getErrorMessage(error: unknown): string {\n if (isAuthError(error)) {\n const errorCode = getErrorCode(error);\n switch (errorCode) {\n case 'USER_EXISTS':\n return 'This email is already taken. Please use a different email.';\n case 'VERIFICATION_EXPIRED':\n return 'Verification code has expired. Please request a new one.';\n case 'VERIFICATION_MISMATCH':\n return 'Invalid verification code. Please try again.';\n case 'VERIFICATION_NOT_FOUND':\n return 'Verification not found. Please request a new code.';\n default:\n return error.message || 'An error occurred. Please try again.';\n }\n }\n if (error instanceof Error) {\n return error.message;\n }\n return 'An error occurred. Please try again.';\n}\n\ntype VerifyChangeEmailFormProps = {\n email: string;\n verificationId: string | null;\n onSuccess: () => void;\n onCancel: () => void;\n};\n\nexport function VerifyChangeEmailForm({\n email,\n verificationId,\n onSuccess,\n onCancel,\n}: VerifyChangeEmailFormProps) {\n const { refresh } = useSession();\n const { hooks } = useApi();\n const [isSubmitting, setIsSubmitting] = useState(false);\n const [currentVerificationId, setCurrentVerificationId] =\n useState(verificationId);\n\n const verifyEmailMutation = hooks.useMutation(\n 'post',\n '/email/verification/confirm',\n );\n const updateEmailMutation = hooks.useMutation('put', '/profile/email');\n const requestEmailVerificationMutation = hooks.useMutation(\n 'post',\n '/email/verification/request',\n );\n\n const onOtpSubmit = async (code: string) => {\n if (!currentVerificationId) {\n toast.error('Verification not found. Please request a new code.');\n return;\n }\n try {\n setIsSubmitting(true);\n\n // Verify email\n await verifyEmailMutation.mutateAsync({\n body: {\n verificationId: currentVerificationId,\n code,\n },\n });\n\n // Update email via auth client\n await updateEmailMutation.mutateAsync({\n body: { email },\n });\n\n toast.success('Email updated successfully');\n await refresh();\n onSuccess();\n } catch (error) {\n const errorMessage = getErrorMessage(error);\n toast.error(errorMessage);\n } finally {\n setIsSubmitting(false);\n }\n };\n\n if (!currentVerificationId) {\n toast.error('Verification not found. Please request a new code.');\n return null;\n }\n\n return (\n <OtpVerificationModal\n open\n title=\"Verify email\"\n description={`Enter the verification code sent to ${email}`}\n verificationId={currentVerificationId}\n isLoading={isSubmitting}\n onSubmit={onOtpSubmit}\n onResend={async () => {\n try {\n setIsSubmitting(true);\n const next = await requestEmailVerificationMutation.mutateAsync({\n body: { email },\n });\n setCurrentVerificationId(next.data?.verificationId ?? null);\n toast.success('Verification code resent');\n } catch (error) {\n toast.error(getErrorMessage(error));\n } finally {\n setIsSubmitting(false);\n }\n }}\n onCancel={onCancel}\n />\n );\n}\n","'use client';\n\nimport {\n Dialog,\n DialogContent,\n DialogDescription,\n DialogHeader,\n DialogTitle,\n} from '@mesob/ui/components';\nimport { VerificationForm } from '../auth/verification-form';\n\ntype OtpVerificationModalProps = {\n open: boolean;\n title: string;\n description?: string;\n verificationId: string;\n isLoading?: boolean;\n onSubmit: (code: string) => Promise<void> | void;\n onResend?: () => Promise<void> | void;\n onCancel?: () => void;\n};\n\nexport function OtpVerificationModal({\n open,\n title,\n description,\n verificationId,\n isLoading,\n onSubmit,\n onResend,\n onCancel,\n}: OtpVerificationModalProps) {\n return (\n <Dialog\n open={open}\n onOpenChange={(nextOpen: boolean) => {\n if (!nextOpen) {\n onCancel?.();\n }\n }}\n >\n <DialogContent>\n <DialogHeader>\n <DialogTitle>{title}</DialogTitle>\n {description && <DialogDescription>{description}</DialogDescription>}\n </DialogHeader>\n\n <VerificationForm\n verificationId={verificationId}\n isLoading={isLoading}\n onSubmit={async ({ code }: { code: string }) => onSubmit(code)}\n onResend={onResend ?? (() => undefined)}\n />\n </DialogContent>\n </Dialog>\n );\n}\n","'use client';\n\nimport { zodResolver } from '@hookform/resolvers/zod';\nimport {\n Button,\n Form,\n FormControl,\n FormField,\n FormItem,\n FormLabel,\n FormMessage,\n InputOTP,\n InputOTPGroup,\n InputOTPSlot,\n} from '@mesob/ui/components';\nimport { useForm } from 'react-hook-form';\nimport { z } from 'zod';\nimport { useTranslator } from '../../hooks/use-translator';\nimport type { AuthErrorContent } from '../../utils/handle-error';\nimport { Countdown } from './countdown';\n\ntype VerificationFormValues = {\n code: string;\n};\n\ntype VerificationFormProps = {\n verificationId: string;\n onSubmit: (values: VerificationFormValues) => Promise<void> | void;\n onResend: () => Promise<void> | void;\n isLoading?: boolean;\n error?: AuthErrorContent | string | null;\n};\n\nconst verificationSchema = (t: (key: string) => string) =>\n z.object({\n code: z.string().length(6, t('form.codeLength')),\n });\n\nexport const VerificationForm = ({\n onSubmit,\n onResend,\n isLoading = false,\n}: VerificationFormProps) => {\n const t = useTranslator('Auth.verification');\n const form = useForm<VerificationFormValues>({\n resolver: zodResolver(verificationSchema(t)),\n defaultValues: { code: '' },\n });\n\n const handleSubmit = form.handleSubmit(async (values) => {\n await onSubmit(values);\n });\n\n const codeLength = form.watch('code').length;\n\n return (\n <Form {...form}>\n <form\n id=\"verification-form\"\n onSubmit={handleSubmit}\n className=\"space-y-4\"\n >\n <FormField\n control={form.control}\n name=\"code\"\n render={({ field }) => (\n <FormItem>\n <div className=\"flex justify-center\">\n <FormLabel>{t('form.codeLabel')}</FormLabel>\n </div>\n <FormControl>\n <InputOTP\n maxLength={6}\n required\n value={field.value ?? ''}\n onChange={field.onChange}\n onBlur={field.onBlur}\n containerClassName=\"gap-4 justify-center mb-2 flex items-center\"\n >\n <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\">\n <InputOTPSlot className=\"h-12\" index={0} />\n <InputOTPSlot className=\"h-12\" index={1} />\n <InputOTPSlot className=\"h-12\" index={2} />\n <InputOTPSlot className=\"h-12\" index={3} />\n <InputOTPSlot className=\"h-12\" index={4} />\n <InputOTPSlot className=\"h-12\" index={5} />\n </InputOTPGroup>\n </InputOTP>\n </FormControl>\n <FormMessage />\n </FormItem>\n )}\n />\n <Button\n type=\"submit\"\n form=\"verification-form\"\n className=\"w-full\"\n disabled={isLoading || codeLength !== 6}\n loading={isLoading}\n >\n {t('form.confirm')}\n </Button>\n <div className=\"flex justify-center\">\n <Countdown onResend={onResend} resending={isLoading} />\n </div>\n </form>\n </Form>\n );\n};\n","import { useMesob } from '@mesob/ui/providers';\nimport { createTranslator } from '../lib/translations';\nimport { useConfig } from '../provider';\n\nexport function useTranslator(namespace?: string) {\n const mesob = useMesob();\n const { config } = useConfig();\n\n if (mesob?.t) {\n return (key: string, params?: Record<string, string | number>): string => {\n const fullKey = namespace ? `${namespace}.${key}` : key;\n return mesob.t?.(fullKey, params) ?? fullKey;\n };\n }\n\n return createTranslator(config.messages || {}, namespace);\n}\n","'use client';\n\nimport { Spinner } from '@mesob/ui/components';\nimport { useEffect, useState } from 'react';\nimport { useTranslator } from '../../hooks/use-translator';\n\ntype CountdownProps = {\n initialSeconds?: number;\n onResend: () => Promise<void> | void;\n resending?: boolean;\n};\n\nexport const Countdown = ({\n initialSeconds = 60,\n onResend,\n resending = false,\n}: CountdownProps) => {\n const t = useTranslator('Common');\n const [seconds, setSeconds] = useState(initialSeconds);\n const [isResending, setIsResending] = useState(false);\n\n useEffect(() => {\n if (seconds <= 0) {\n return;\n }\n const timer = setInterval(() => {\n setSeconds((prev) => {\n if (prev <= 1) {\n clearInterval(timer);\n return 0;\n }\n return prev - 1;\n });\n }, 1000);\n return () => clearInterval(timer);\n }, [seconds]);\n\n const handleResend = async () => {\n setIsResending(true);\n try {\n await onResend();\n setSeconds(initialSeconds);\n } catch (_error) {\n // handled by parent\n } finally {\n setIsResending(false);\n }\n };\n\n const busy = isResending || resending;\n\n if (seconds > 0) {\n return (\n <p className=\"text-sm text-muted-foreground\">\n {t('resendIn', { seconds })}\n </p>\n );\n }\n\n return (\n <button\n type=\"button\"\n onClick={handleResend}\n disabled={busy}\n className=\"text-sm text-primary hover:underline disabled:opacity-50 flex items-center gap-1\"\n >\n {busy && <Spinner className=\"h-3 w-3\" />}\n {t('resend')}\n </button>\n );\n};\n"],"mappings":";;;AAEA;AAAA,EACE,UAAAA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,uBAAuB;AAChC,SAAS,YAAAC,iBAAgB;;;ACPzB,SAAS,aAAa,2BAA2B;AACjD,SAAS,iBAAiB;AAC1B,OAAO,uBAAuB;AAC9B,OAAO,kBAAkB;AAEzB,SAAS,eAAe,YAAY,SAAS,gBAAgB;;;ACLtD,SAAS,iBAAiB,UAAoB,WAAoB;AACvE,SAAO,CAAC,KAAa,WAAqD;AACxE,UAAM,UAAU,YAAY,GAAG,SAAS,IAAI,GAAG,KAAK;AACpD,UAAM,OAAO,QAAQ,MAAM,GAAG;AAE9B,QAAI,QAAiB;AACrB,eAAW,KAAK,MAAM;AACpB,UAAI,SAAS,OAAO,UAAU,YAAY,UAAU,MAAM;AACxD,gBAAS,MAAkC,CAAC;AAAA,MAC9C,OAAO;AACL,eAAO;AAAA,MACT;AAAA,IACF;AAEA,QAAI,OAAO,UAAU,UAAU;AAC7B,aAAO;AAAA,IACT;AAGA,QAAI,QAAQ;AACV,aAAO,MAAM;AAAA,QAAQ;AAAA,QAAc,CAAC,GAAG,UACrC,OAAO,OAAO,KAAK,KAAK,IAAI,KAAK,GAAG;AAAA,MACtC;AAAA,IACF;AAEA,WAAO;AAAA,EACT;AACF;;;AC3BA,IAAM,eACJ,OAAO,YAAY,eAAe,QAAQ,IAAI,aAAa;;;AF4JvD;AA1FN,IAAM,iBAAiB,cAA0C,IAAI;AACrE,IAAM,aAAa,cAAsC,IAAI;AAC7D,IAAM,gBAAgB,cA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0BAAAF,MAAC,SAAI,WAAU,6BACb;AAAA,4BAAAD,KAAC,UAAK,WAAU,eAAe,iBAAM;AAAA,YACrC,gBAAAA,KAAC,UAAK,WAAU,iCAAiC,uBAAY;AAAA,aAC/D;AAAA,UACA,gBAAAA;AAAA,YAAC;AAAA;AAAA,cACC,WAAW,gCACT,SAAS,eAAe,EAC1B;AAAA;AAAA,UACF;AAAA;AAAA;AAAA,IACF;AAAA,IAEA,gBAAAA,KAAC,sBACE,oBACC,gBAAAA;AAAA,MAAC;AAAA;AAAA,QACC,OAAO;AAAA,QACP;AAAA,QACA,WAAW;AAAA,QACX,UAAU;AAAA;AAAA,IACZ,IAEA,gBAAAA;AAAA,MAAC;AAAA;AAAA,QACC,WAAW;AAAA,QACX,UAAU;AAAA,QACV,YAAY;AAAA;AAAA,IACd,GAEJ;AAAA,KACF,GACF;AAEJ;","names":["Button","useState","useState","jsx","useState","useState","toast","zodResolver","Button","useForm","z","Spinner","useEffect","useState","jsx","jsxs","useState","useEffect","Spinner","jsx","jsxs","z","useForm","zodResolver","Button","jsx","jsxs","jsx","isAuthError","getErrorCode","getErrorMessage","useState","toast","jsx","jsxs","useState","Button"]}
@@ -2,7 +2,7 @@
2
2
 
3
3
  // src/components/profile/change-phone-form.tsx
4
4
  import {
5
- Button as Button4,
5
+ Button as Button3,
6
6
  Collapsible,
7
7
  CollapsibleContent,
8
8
  CollapsibleTrigger
@@ -375,7 +375,7 @@ import {
375
375
  // src/components/auth/verification-form.tsx
376
376
  import { zodResolver as zodResolver2 } from "@hookform/resolvers/zod";
377
377
  import {
378
- Button as Button3,
378
+ Button as Button2,
379
379
  Form,
380
380
  FormControl,
381
381
  FormField,
@@ -384,8 +384,7 @@ import {
384
384
  FormMessage,
385
385
  InputOTP,
386
386
  InputOTPGroup,
387
- InputOTPSlot,
388
- Spinner as Spinner3
387
+ InputOTPSlot
389
388
  } from "@mesob/ui/components";
390
389
  import { useForm as useForm2 } from "react-hook-form";
391
390
  import { z as z2 } from "zod";
@@ -405,7 +404,7 @@ function useTranslator(namespace) {
405
404
  }
406
405
 
407
406
  // src/components/auth/countdown.tsx
408
- import { Button as Button2, Spinner as Spinner2 } from "@mesob/ui/components";
407
+ import { Spinner as Spinner2 } from "@mesob/ui/components";
409
408
  import { useEffect as useEffect2, useState as useState3 } from "react";
410
409
  import { jsx as jsx3, jsxs as jsxs2 } from "react/jsx-runtime";
411
410
  var Countdown = ({
@@ -441,17 +440,19 @@ var Countdown = ({
441
440
  setIsResending(false);
442
441
  }
443
442
  };
443
+ const busy = isResending || resending;
444
444
  if (seconds > 0) {
445
- return /* @__PURE__ */ jsx3(Button2, { variant: "ghost", disabled: true, children: t("resendIn", { seconds }) });
445
+ return /* @__PURE__ */ jsx3("p", { className: "text-sm text-muted-foreground", children: t("resendIn", { seconds }) });
446
446
  }
447
447
  return /* @__PURE__ */ jsxs2(
448
- Button2,
448
+ "button",
449
449
  {
450
- variant: "ghost",
450
+ type: "button",
451
451
  onClick: handleResend,
452
- disabled: isResending || resending,
452
+ disabled: busy,
453
+ className: "text-sm text-primary hover:underline disabled:opacity-50 flex items-center gap-1",
453
454
  children: [
454
- isResending || resending && /* @__PURE__ */ jsx3(Spinner2, {}),
455
+ busy && /* @__PURE__ */ jsx3(Spinner2, { className: "h-3 w-3" }),
455
456
  t("resend")
456
457
  ]
457
458
  }
@@ -471,13 +472,12 @@ var VerificationForm = ({
471
472
  const t = useTranslator("Auth.verification");
472
473
  const form = useForm2({
473
474
  resolver: zodResolver2(verificationSchema(t)),
474
- defaultValues: {
475
- code: ""
476
- }
475
+ defaultValues: { code: "" }
477
476
  });
478
477
  const handleSubmit = form.handleSubmit(async (values) => {
479
478
  await onSubmit(values);
480
479
  });
480
+ const codeLength = form.watch("code").length;
481
481
  return /* @__PURE__ */ jsx4(Form, { ...form, children: /* @__PURE__ */ jsxs3(
482
482
  "form",
483
483
  {
@@ -515,21 +515,18 @@ var VerificationForm = ({
515
515
  ] })
516
516
  }
517
517
  ),
518
- /* @__PURE__ */ jsxs3("div", { className: "flex justify-between items-center", children: [
519
- /* @__PURE__ */ jsx4(Countdown, { onResend, resending: isLoading }),
520
- /* @__PURE__ */ jsxs3(
521
- Button3,
522
- {
523
- type: "submit",
524
- form: "verification-form",
525
- disabled: isLoading || form.watch("code").length !== 6,
526
- children: [
527
- isLoading && /* @__PURE__ */ jsx4(Spinner3, {}),
528
- t("form.confirm")
529
- ]
530
- }
531
- )
532
- ] })
518
+ /* @__PURE__ */ jsx4(
519
+ Button2,
520
+ {
521
+ type: "submit",
522
+ form: "verification-form",
523
+ className: "w-full",
524
+ disabled: isLoading || codeLength !== 6,
525
+ loading: isLoading,
526
+ children: t("form.confirm")
527
+ }
528
+ ),
529
+ /* @__PURE__ */ jsx4("div", { className: "flex justify-center", children: /* @__PURE__ */ jsx4(Countdown, { onResend, resending: isLoading }) })
533
530
  ]
534
531
  }
535
532
  ) });
@@ -737,7 +734,7 @@ function ChangePhoneForm() {
737
734
  CollapsibleTrigger,
738
735
  {
739
736
  render: /* @__PURE__ */ jsx7(
740
- Button4,
737
+ Button3,
741
738
  {
742
739
  variant: "ghost",
743
740
  className: "w-full justify-between p-4 h-auto"