@mesob/auth-react 0.3.5 → 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.
- package/dist/components/auth/forgot-password.js +5 -1
- package/dist/components/auth/forgot-password.js.map +1 -1
- package/dist/components/auth/reset-password-form.js +5 -1
- package/dist/components/auth/reset-password-form.js.map +1 -1
- package/dist/components/auth/set-password.d.ts +9 -0
- package/dist/components/auth/set-password.js +527 -0
- package/dist/components/auth/set-password.js.map +1 -0
- package/dist/components/auth/sign-in.js +22 -1
- package/dist/components/auth/sign-in.js.map +1 -1
- package/dist/components/auth/sign-up.js +7 -5
- package/dist/components/auth/sign-up.js.map +1 -1
- package/dist/components/auth/verify-email.js +5 -1
- package/dist/components/auth/verify-email.js.map +1 -1
- package/dist/components/auth/verify-phone.js +5 -1
- package/dist/components/auth/verify-phone.js.map +1 -1
- package/dist/components/authorization/deny.d.ts +11 -0
- package/dist/components/authorization/deny.js +52 -0
- package/dist/components/authorization/deny.js.map +1 -0
- package/dist/components/authorization/grant.d.ts +12 -0
- package/dist/components/authorization/grant.js +57 -0
- package/dist/components/authorization/grant.js.map +1 -0
- package/dist/components/error-boundary.d.ts +2 -2
- package/dist/components/iam/permission-selector.d.ts +19 -0
- package/dist/components/iam/permission-selector.js +122 -0
- package/dist/components/iam/permission-selector.js.map +1 -0
- package/dist/components/iam/permissions.js +12 -31
- package/dist/components/iam/permissions.js.map +1 -1
- package/dist/components/iam/role-detail-layout.d.ts +11 -0
- package/dist/components/iam/role-detail-layout.js +137 -0
- package/dist/components/iam/role-detail-layout.js.map +1 -0
- package/dist/components/iam/role-detail-page.d.ts +9 -0
- package/dist/components/iam/role-detail-page.js +229 -0
- package/dist/components/iam/role-detail-page.js.map +1 -0
- package/dist/components/iam/role-permissions-page.d.ts +8 -0
- package/dist/components/iam/role-permissions-page.js +397 -0
- package/dist/components/iam/role-permissions-page.js.map +1 -0
- package/dist/components/iam/roles.js +11 -8
- package/dist/components/iam/roles.js.map +1 -1
- package/dist/components/iam/users.js +1 -7
- package/dist/components/iam/users.js.map +1 -1
- package/dist/components/profile/account.js +110 -19
- package/dist/components/profile/account.js.map +1 -1
- package/dist/components/profile/change-profile.d.ts +2 -1
- package/dist/components/profile/change-profile.js +16 -8
- package/dist/components/profile/change-profile.js.map +1 -1
- package/dist/components/profile/security.js +51 -17
- package/dist/components/profile/security.js.map +1 -1
- package/dist/index.d.ts +9 -1
- package/dist/index.js +1813 -725
- package/dist/index.js.map +1 -1
- package/dist/pages/auth/forgot-password.d.ts +7 -0
- package/dist/pages/auth/forgot-password.js +784 -0
- package/dist/pages/auth/forgot-password.js.map +1 -0
- package/dist/pages/auth/layout.d.ts +8 -0
- package/dist/pages/auth/layout.js +562 -0
- package/dist/pages/auth/layout.js.map +1 -0
- package/dist/pages/auth/reset-password.d.ts +10 -0
- package/dist/pages/auth/reset-password.js +913 -0
- package/dist/pages/auth/reset-password.js.map +1 -0
- package/dist/pages/auth/set-password.d.ts +10 -0
- package/dist/pages/auth/set-password.js +946 -0
- package/dist/pages/auth/set-password.js.map +1 -0
- package/dist/pages/auth/sign-in.d.ts +10 -0
- package/dist/pages/auth/sign-in.js +984 -0
- package/dist/pages/auth/sign-in.js.map +1 -0
- package/dist/pages/auth/sign-up.d.ts +10 -0
- package/dist/pages/auth/sign-up.js +940 -0
- package/dist/pages/auth/sign-up.js.map +1 -0
- package/dist/pages/auth/verify-email.d.ts +10 -0
- package/dist/pages/auth/verify-email.js +950 -0
- package/dist/pages/auth/verify-email.js.map +1 -0
- package/dist/pages/auth/verify-phone.d.ts +10 -0
- package/dist/pages/auth/verify-phone.js +964 -0
- package/dist/pages/auth/verify-phone.js.map +1 -0
- package/dist/pages/iam/permissions.d.ts +5 -0
- package/dist/pages/iam/permissions.js +308 -0
- package/dist/pages/iam/permissions.js.map +1 -0
- package/dist/pages/iam/role-detail-layout.d.ts +12 -0
- package/dist/pages/iam/role-detail-layout.js +145 -0
- package/dist/pages/iam/role-detail-layout.js.map +1 -0
- package/dist/pages/iam/role-detail.d.ts +12 -0
- package/dist/pages/iam/role-detail.js +241 -0
- package/dist/pages/iam/role-detail.js.map +1 -0
- package/dist/pages/iam/role-permissions.d.ts +12 -0
- package/dist/pages/iam/role-permissions.js +409 -0
- package/dist/pages/iam/role-permissions.js.map +1 -0
- package/dist/pages/iam/role-users.d.ts +12 -0
- package/dist/pages/iam/role-users.js +825 -0
- package/dist/pages/iam/role-users.js.map +1 -0
- package/dist/pages/iam/roles.d.ts +5 -0
- package/dist/pages/iam/roles.js +684 -0
- package/dist/pages/iam/roles.js.map +1 -0
- package/dist/pages/iam/sessions.d.ts +5 -0
- package/dist/pages/iam/sessions.js +315 -0
- package/dist/pages/iam/sessions.js.map +1 -0
- package/dist/pages/iam/tenant-detail.d.ts +10 -0
- package/dist/pages/iam/tenant-detail.js +186 -0
- package/dist/pages/iam/tenant-detail.js.map +1 -0
- package/dist/pages/iam/tenants.d.ts +5 -0
- package/dist/pages/iam/tenants.js +610 -0
- package/dist/pages/iam/tenants.js.map +1 -0
- package/dist/pages/iam/user-activity.d.ts +10 -0
- package/dist/pages/iam/user-activity.js +850 -0
- package/dist/pages/iam/user-activity.js.map +1 -0
- package/dist/pages/iam/user-detail-layout.d.ts +12 -0
- package/dist/pages/iam/user-detail-layout.js +106 -0
- package/dist/pages/iam/user-detail-layout.js.map +1 -0
- package/dist/pages/iam/user-detail.d.ts +10 -0
- package/dist/pages/iam/user-detail.js +102 -0
- package/dist/pages/iam/user-detail.js.map +1 -0
- package/dist/pages/iam/users.d.ts +5 -0
- package/dist/pages/iam/users.js +1275 -0
- package/dist/pages/iam/users.js.map +1 -0
- package/dist/pages/profile/account.d.ts +5 -0
- package/dist/pages/profile/account.js +182 -0
- package/dist/pages/profile/account.js.map +1 -0
- package/dist/pages/profile/layout.d.ts +8 -0
- package/dist/pages/profile/layout.js +133 -0
- package/dist/pages/profile/layout.js.map +1 -0
- package/dist/pages/profile/security.d.ts +5 -0
- package/dist/pages/profile/security.js +1539 -0
- package/dist/pages/profile/security.js.map +1 -0
- package/dist/{types-vcfvnAzQ.d.ts → types-g9QcNRxT.d.ts} +13 -7
- package/package.json +102 -3
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/components/iam/role-permissions-page.tsx","../../../src/provider.tsx","../../../src/utils/cookie.ts","../../../src/components/iam/permission-selector.tsx"],"sourcesContent":["'use client';\n\nimport {\n Badge,\n Button,\n DataTablePagination,\n DeleteConfirmButton,\n DisplayTable,\n EntityEmptyState,\n EntityFilter,\n EntityHeader,\n EntityLoadingState,\n EntitySearch,\n EntitySort,\n EntityViewToggle,\n PageBody,\n Tbody,\n Td,\n Th,\n Thead,\n Tr,\n useEntityPagination,\n useEntityParams,\n} from '@mesob/ui/components';\nimport { IconKey, IconPlus, IconTrash } from '@tabler/icons-react';\nimport { useQueryClient } from '@tanstack/react-query';\nimport type { ReactNode } from 'react';\nimport { useMemo } from 'react';\nimport { toast } from 'sonner';\nimport type { paths } from '../../data/openapi';\nimport { useApi } from '../../provider';\nimport { PermissionSelector } from './permission-selector';\n\ntype Permission = {\n id: string;\n description?: unknown;\n activity: string;\n application: string;\n feature: string;\n};\n\ntype RolePermissionsPageProps = {\n roleId: string;\n};\n\nconst TABLE_COLUMN_COUNT = 4;\n\nexport function RolePermissionsPage({ roleId }: RolePermissionsPageProps) {\n const { hooks } = useApi();\n const qc = useQueryClient();\n const { queryConfig, params, setParams } = useEntityParams({\n searchKey: 'search',\n defaultSort: 'application',\n defaultOrder: 'asc',\n });\n const permissionsQuery = useMemo(\n () =>\n ({\n params: {\n path: { id: roleId },\n query: queryConfig.params.query,\n },\n }) as {\n params: {\n path: { id: string };\n query: NonNullable<\n paths['/roles/{id}/permissions']['get']['parameters']['query']\n >;\n };\n },\n [queryConfig, roleId],\n );\n\n const { data, isPending, isFetching } = hooks.useQuery(\n 'get',\n '/roles/{id}/permissions',\n permissionsQuery,\n { enabled: !!roleId },\n );\n const assignPermissions = hooks.useMutation(\n 'post',\n '/roles/{id}/permissions',\n {\n onSuccess: (result: { created?: number } | undefined) => {\n qc.invalidateQueries({ queryKey: ['get', '/roles'] });\n qc.invalidateQueries({ queryKey: ['get', '/roles/{id}'] });\n qc.invalidateQueries({ queryKey: ['get', '/roles/{id}/permissions'] });\n toast.success(\n result?.created\n ? `${result.created} permission(s) added`\n : 'No changes',\n );\n },\n onError: () => {\n toast.error('Failed to assign permissions');\n },\n },\n );\n const revokePermission = hooks.useMutation(\n 'delete',\n '/roles/{id}/permissions/{permissionId}',\n {\n onSuccess: () => {\n qc.invalidateQueries({ queryKey: ['get', '/roles'] });\n qc.invalidateQueries({ queryKey: ['get', '/roles/{id}'] });\n qc.invalidateQueries({\n queryKey: ['get', '/roles/{id}/permissions'],\n });\n toast.success('Permission removed');\n },\n onError: () => {\n toast.error('Failed to remove permission');\n },\n },\n );\n\n const permissions = (data?.permissions ?? []) as Permission[];\n const { total, pageCount } = useEntityPagination({\n items: permissions,\n total: data?.total,\n pageSize: params.pageSize,\n });\n const isLoading = isPending || isFetching;\n const currentView = (params.view || 'table') as 'table' | 'card';\n\n if (!roleId) {\n return null;\n }\n\n let content: ReactNode;\n if (isLoading) {\n content = (\n <EntityLoadingState\n view={currentView}\n rowCount={params.pageSize}\n columnCount={TABLE_COLUMN_COUNT}\n cardCount={params.pageSize}\n />\n );\n } else if (total === 0) {\n content = (\n <EntityEmptyState\n icon={IconKey}\n entityName=\"permission\"\n title=\"No permissions assigned\"\n description=\"Assign permissions from the selector to grant access to this role.\"\n />\n );\n } else if (currentView === 'table') {\n content = (\n <div className=\"space-y-4\">\n <DisplayTable withTableBorder>\n <Thead>\n <Tr>\n <Th>Permission</Th>\n <Th>Application</Th>\n <Th>Feature</Th>\n <Th className=\"w-[60px]\" />\n </Tr>\n </Thead>\n <Tbody>\n {permissions.map((permission) => (\n <Tr key={permission.id}>\n <Td>\n <div className=\"space-y-1\">\n <p className=\"font-medium\">{permission.activity}</p>\n <p className=\"font-mono text-xs text-muted-foreground\">\n {permission.id}\n </p>\n </div>\n </Td>\n <Td>\n <Badge variant=\"secondary\">{permission.application}</Badge>\n </Td>\n <Td>\n <Badge variant=\"outline\">{permission.feature}</Badge>\n </Td>\n <Td>\n <DeleteConfirmButton\n entityName=\"permission\"\n onConfirm={() =>\n revokePermission.mutate({\n params: {\n path: { id: roleId, permissionId: permission.id },\n },\n })\n }\n triggerClassName=\"size-8 text-destructive hover:text-destructive\"\n />\n </Td>\n </Tr>\n ))}\n </Tbody>\n </DisplayTable>\n <DataTablePagination\n pageIndex={params.page - 1}\n pageSize={params.pageSize}\n pageCount={pageCount}\n totalRows={total}\n onPageChange={(page) => setParams({ page: page + 1 })}\n onPageSizeChange={(pageSize) => setParams({ pageSize, page: 1 })}\n />\n </div>\n );\n } else {\n content = (\n <div className=\"space-y-4\">\n <div className=\"grid grid-cols-1 gap-4 md:grid-cols-2 xl:grid-cols-3\">\n {permissions.map((permission) => (\n <div\n key={permission.id}\n className=\"rounded-xl border border-border/60 bg-card p-4 shadow-sm\"\n >\n <div className=\"flex items-start justify-between gap-3\">\n <div className=\"space-y-2\">\n <p className=\"font-semibold\">{permission.activity}</p>\n <div className=\"flex flex-wrap gap-2\">\n <Badge variant=\"secondary\">{permission.application}</Badge>\n <Badge variant=\"outline\">{permission.feature}</Badge>\n </div>\n <p className=\"font-mono text-xs text-muted-foreground\">\n {permission.id}\n </p>\n </div>\n <Button\n type=\"button\"\n variant=\"ghost\"\n size=\"icon\"\n onClick={() =>\n revokePermission.mutate({\n params: {\n path: { id: roleId, permissionId: permission.id },\n },\n })\n }\n disabled={revokePermission.isPending}\n >\n <IconTrash className=\"h-4 w-4\" />\n </Button>\n </div>\n </div>\n ))}\n </div>\n <DataTablePagination\n pageIndex={params.page - 1}\n pageSize={params.pageSize}\n pageCount={pageCount}\n totalRows={total}\n onPageChange={(page) => setParams({ page: page + 1 })}\n onPageSizeChange={(pageSize) => setParams({ pageSize, page: 1 })}\n />\n </div>\n );\n }\n\n return (\n <PageBody className=\"px-0 pb-6\">\n <EntityHeader\n icon={<IconKey className=\"h-5 w-5\" />}\n title=\"Role permissions\"\n actions={\n <PermissionSelector\n trigger={\n <Button size=\"sm\" loading={assignPermissions.isPending}>\n <IconPlus className=\"h-4 w-4\" />\n Add permissions\n </Button>\n }\n onSelect={(selectedPermissions) => {\n if (!selectedPermissions.length) {\n return;\n }\n\n assignPermissions.mutate({\n params: { path: { id: roleId } },\n body: {\n permissionIds: selectedPermissions.map(\n (permission) => permission.id,\n ),\n },\n });\n }}\n excludeIds={permissions.map((permission) => permission.id)}\n />\n }\n search={\n <EntitySearch\n paramKey=\"search\"\n placeholder=\"Search assigned permissions...\"\n />\n }\n filter={\n <EntityFilter\n options={[\n { label: 'All', value: '' },\n { label: 'Application', value: 'application' },\n { label: 'Feature', value: 'feature' },\n { label: 'Activity', value: 'activity' },\n ]}\n placeholder=\"Search field\"\n />\n }\n sort={\n <EntitySort\n defaultSort=\"application\"\n defaultOrder=\"asc\"\n options={[\n { label: 'ID', value: 'id' },\n { label: 'Application', value: 'application' },\n { label: 'Feature', value: 'feature' },\n { label: 'Activity', value: 'activity' },\n ]}\n />\n }\n view={<EntityViewToggle views={['table', 'card']} />}\n />\n {content}\n </PageBody>\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","'use client';\n\nimport {\n Badge,\n EntitySelector,\n type EntitySelectorColumn,\n type EntitySelectorConfig,\n useEntitySectionState,\n} from '@mesob/ui/components';\nimport { IconKey } from '@tabler/icons-react';\nimport type { ReactNode } from 'react';\nimport type { paths } from '../../data/openapi';\nimport { useApi } from '../../provider';\n\ntype Permission = {\n id: string;\n description?: unknown;\n activity: string;\n application: string;\n feature: string;\n};\n\nconst permissionColumns: EntitySelectorColumn<Permission>[] = [\n {\n key: 'permission',\n header: 'Permission',\n cell: (permission) => (\n <div className=\"space-y-1\">\n <p className=\"font-medium\">{permission.activity}</p>\n <p className=\"font-mono text-xs text-muted-foreground\">\n {permission.id}\n </p>\n </div>\n ),\n },\n {\n key: 'scope',\n header: 'Scope',\n cell: (permission) => (\n <div className=\"flex flex-wrap gap-2\">\n <Badge variant=\"secondary\">{permission.application}</Badge>\n <Badge variant=\"outline\">{permission.feature}</Badge>\n </div>\n ),\n },\n];\n\ntype PermissionSelectorProps = {\n trigger: ReactNode;\n multiple?: boolean;\n onSelect: (permissions: Permission[]) => void;\n excludeIds?: string[];\n};\n\nexport function PermissionSelector({\n trigger,\n multiple = true,\n onSelect,\n excludeIds = [],\n}: PermissionSelectorProps) {\n const { hooks } = useApi();\n const state = useEntitySectionState({\n defaultSort: 'id',\n defaultOrder: 'asc',\n defaultPageSize: 10,\n searchParamName: 'search',\n });\n const permissionsQuery = state.queryConfig as {\n params: {\n query: NonNullable<paths['/permissions']['get']['parameters']['query']>;\n };\n };\n\n const { data, isPending, isFetching } = hooks.useQuery(\n 'get',\n '/permissions',\n permissionsQuery,\n );\n\n const items = ((data?.permissions ?? []) as Permission[]).filter(\n (permission) => !excludeIds.includes(permission.id),\n );\n\n const config: EntitySelectorConfig<Permission> = {\n title: 'Select permission(s)',\n multiple,\n entityName: 'permission',\n entityIcon: IconKey,\n columns: permissionColumns,\n getItemLabel: (permission) => permission.id,\n searchPlaceholder: 'Search permissions...',\n filterOptions: [\n { label: 'All', value: '' },\n { label: 'Application', value: 'application' },\n { label: 'Feature', value: 'feature' },\n { label: 'Activity', value: 'activity' },\n ],\n sortOptions: [\n { label: 'ID', value: 'id' },\n { label: 'Application', value: 'application' },\n { label: 'Feature', value: 'feature' },\n { label: 'Activity', value: 'activity' },\n ],\n showViewToggle: false,\n wrapHeaderInCard: false,\n };\n\n return (\n <EntitySelector<Permission>\n trigger={trigger}\n config={config}\n onSelect={onSelect}\n items={items}\n total={items.length}\n isLoading={isPending || isFetching}\n state={state}\n />\n );\n}\n"],"mappings":";;;AAEA;AAAA,EACE,SAAAA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,WAAAC,UAAS,UAAU,iBAAiB;AAC7C,SAAS,sBAAsB;AAE/B,SAAS,WAAAC,gBAAe;AACxB,SAAS,aAAa;;;AC1BtB,SAAS,aAAa,2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
|
},
|
|
154
154
|
{
|
|
155
|
-
key: "
|
|
156
|
-
header: "
|
|
157
|
-
cell: (role) => /* @__PURE__ */
|
|
155
|
+
key: "access",
|
|
156
|
+
header: "Access",
|
|
157
|
+
cell: (role) => /* @__PURE__ */ jsxs3("div", { className: "flex flex-wrap gap-2", children: [
|
|
158
|
+
role.isSystem ? /* @__PURE__ */ jsx4(Badge, { children: "System" }) : null,
|
|
159
|
+
/* @__PURE__ */ jsxs3(Badge, { variant: "secondary", children: [
|
|
160
|
+
role.permissionCount ?? 0,
|
|
161
|
+
" permissions"
|
|
162
|
+
] })
|
|
163
|
+
] })
|
|
158
164
|
},
|
|
159
165
|
{
|
|
160
166
|
key: "createdAt",
|
|
@@ -164,10 +170,7 @@ function Roles() {
|
|
|
164
170
|
{
|
|
165
171
|
key: "actions",
|
|
166
172
|
header: "Actions",
|
|
167
|
-
cell: (_role) => /* @__PURE__ */
|
|
168
|
-
/* @__PURE__ */ jsx4(Button, { variant: "outline", size: "sm", children: "Permissions" }),
|
|
169
|
-
/* @__PURE__ */ jsx4(Button, { variant: "outline", size: "sm", children: "Edit" })
|
|
170
|
-
] })
|
|
173
|
+
cell: (_role) => /* @__PURE__ */ jsx4("div", { className: "flex gap-2", children: /* @__PURE__ */ jsx4(Button, { variant: "outline", size: "sm", children: "Edit" }) })
|
|
171
174
|
}
|
|
172
175
|
];
|
|
173
176
|
if (error) {
|
|
@@ -177,7 +180,7 @@ function Roles() {
|
|
|
177
180
|
/* @__PURE__ */ jsxs3("div", { className: "flex justify-between items-center", children: [
|
|
178
181
|
/* @__PURE__ */ jsxs3("div", { children: [
|
|
179
182
|
/* @__PURE__ */ jsx4("h1", { className: "text-3xl font-bold", children: "Roles" }),
|
|
180
|
-
/* @__PURE__ */ jsx4("p", { className: "text-muted-foreground", children: "Manage
|
|
183
|
+
/* @__PURE__ */ jsx4("p", { className: "text-muted-foreground", children: "Manage roles and assigned permissions" })
|
|
181
184
|
] }),
|
|
182
185
|
/* @__PURE__ */ jsx4(Button, { children: "Create Role" })
|
|
183
186
|
] }),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/components/iam/roles.tsx","../../../src/provider.tsx","../../../src/utils/cookie.ts","../../../src/components/shared/data-table.tsx","../../../src/components/skeletons/table-skeleton.tsx"],"sourcesContent":["'use client';\n\nimport { Badge, Button } from '@mesob/ui/components';\nimport { useLocale } from 'next-intl';\nimport { useState } from 'react';\nimport { useApi } from '../../provider';\nimport { DataTable, type DataTableColumn } from '../shared/data-table';\n\n// Role type from OpenAPI schema\ntype Role = {\n id: string;\n code: string;\n name: string | { am?: string; en?: string };\n description: string | { am?: string; en?: string };\n createdAt: string;\n};\n\nfunction getTranslation(\n value: string | { am?: string; en?: string } | null | undefined,\n locale: string,\n): string {\n if (!value) {\n return '';\n }\n if (typeof value === 'string') {\n return value;\n }\n if (typeof value === 'object') {\n return value[locale as 'am' | 'en'] ?? value.en ?? value.am ?? '';\n }\n return '';\n}\n\nexport function Roles() {\n const { hooks } = useApi();\n const locale = useLocale();\n const [page, setPage] = useState(1);\n const limit = 20;\n\n // Use openapi-react-query hooks\n const { data, isLoading, error } = hooks.useQuery('get', '/roles', {\n params: {\n query: {\n page: String(page),\n limit: String(limit),\n },\n },\n });\n\n const columns: DataTableColumn<Role>[] = [\n {\n key: 'name',\n header: 'Role',\n cell: (role) => (\n <div>\n <p className=\"font-medium\">{getTranslation(role.name, locale)}</p>\n <Badge variant=\"outline\" className=\"mt-1\">\n {role.code}\n </Badge>\n </div>\n ),\n },\n {\n key: 'description',\n header: 'Description',\n cell: (role) => (\n <p className=\"text-sm text-muted-foreground\">\n {getTranslation(role.description, locale)}\n </p>\n ),\n },\n {\n key: 'createdAt',\n header: 'Created',\n cell: (role) => (\n <p className=\"text-sm\">\n {new Date(role.createdAt).toLocaleDateString()}\n </p>\n ),\n },\n {\n key: 'actions',\n header: 'Actions',\n cell: (_role) => (\n <div className=\"flex gap-2\">\n <Button variant=\"outline\" size=\"sm\">\n Permissions\n </Button>\n <Button variant=\"outline\" size=\"sm\">\n Edit\n </Button>\n </div>\n ),\n },\n ];\n\n if (error) {\n return (\n <div className=\"p-6 text-center\">\n <p className=\"text-destructive\">Error loading roles</p>\n </div>\n );\n }\n\n return (\n <div className=\"w-full p-6 space-y-4\">\n <div className=\"flex justify-between items-center\">\n <div>\n <h1 className=\"text-3xl font-bold\">Roles</h1>\n <p className=\"text-muted-foreground\">Manage user roles</p>\n </div>\n <Button>Create Role</Button>\n </div>\n\n <DataTable\n data={(data as { roles: Role[] })?.roles || []}\n columns={columns}\n isLoading={isLoading}\n emptyMessage=\"No roles found\"\n />\n\n {data &&\n 'roles' in data &&\n data.roles &&\n (data.roles as Role[]).length >= limit && (\n <div className=\"flex justify-between items-center\">\n <Button\n variant=\"outline\"\n disabled={page === 1}\n onClick={() => setPage((prev) => prev - 1)}\n >\n Previous\n </Button>\n <span className=\"text-sm text-muted-foreground\">Page {page}</span>\n <Button\n variant=\"outline\"\n onClick={() => setPage((prev) => prev + 1)}\n >\n Next\n </Button>\n </div>\n )}\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","'use client';\n\nimport {\n Table,\n TableBody,\n TableCell,\n TableHead,\n TableHeader,\n TableRow,\n} from '@mesob/ui/components';\nimport type { ReactNode } from 'react';\nimport { TableSkeleton } from '../skeletons/table-skeleton';\n\nexport type DataTableColumn<T> = {\n key: string;\n header: string;\n cell: (row: T) => ReactNode;\n sortable?: boolean;\n};\n\ntype DataTableProps<T> = {\n data: T[];\n columns: DataTableColumn<T>[];\n isLoading?: boolean;\n onRowClick?: (row: T) => void;\n emptyMessage?: string;\n actions?: ReactNode;\n};\n\nexport function DataTable<T extends { id: string }>({\n data,\n columns,\n isLoading,\n onRowClick,\n emptyMessage = 'No data available',\n actions,\n}: DataTableProps<T>) {\n if (isLoading) {\n return <TableSkeleton columns={columns.length} rows={5} />;\n }\n\n if (data.length === 0) {\n return (\n <div className=\"flex flex-col items-center justify-center min-h-[400px] p-6\">\n <p className=\"text-muted-foreground\">{emptyMessage}</p>\n {actions && <div className=\"mt-4\">{actions}</div>}\n </div>\n );\n }\n\n return (\n <div className=\"w-full space-y-4\">\n {actions && <div className=\"flex justify-end\">{actions}</div>}\n\n <div className=\"border rounded-lg overflow-hidden\">\n <Table>\n <TableHeader>\n <TableRow>\n {columns.map((column) => (\n <TableHead key={column.key}>{column.header}</TableHead>\n ))}\n </TableRow>\n </TableHeader>\n <TableBody>\n {data.map((row) => (\n <TableRow\n key={row.id}\n onClick={() => onRowClick?.(row)}\n className={onRowClick ? 'cursor-pointer hover:bg-muted/50' : ''}\n >\n {columns.map((column) => (\n <TableCell key={`${row.id}-${column.key}`}>\n {column.cell(row)}\n </TableCell>\n ))}\n </TableRow>\n ))}\n </TableBody>\n </Table>\n </div>\n </div>\n );\n}\n","'use client';\n\nimport { Skeleton } from '@mesob/ui/components';\n\ntype TableSkeletonProps = {\n columns?: number;\n rows?: number;\n};\n\nexport function TableSkeleton({ columns = 5, rows = 10 }: TableSkeletonProps) {\n const headerKeys = Array.from({ length: columns }, (_, i) => `header-${i}`);\n const rowKeys = Array.from({ length: rows }, (_, i) => `row-${i}`);\n const cellKeys = Array.from({ length: rows }, (_, rowIdx) =>\n Array.from({ length: columns }, (_, colIdx) => `cell-${rowIdx}-${colIdx}`),\n );\n\n return (\n <div className=\"w-full space-y-4\">\n {/* Header */}\n <div className=\"flex justify-between items-center\">\n <Skeleton className=\"h-8 w-48\" />\n <Skeleton className=\"h-10 w-32\" />\n </div>\n\n {/* Search/filters */}\n <div className=\"flex gap-4\">\n <Skeleton className=\"h-10 flex-1 max-w-sm\" />\n <Skeleton className=\"h-10 w-24\" />\n <Skeleton className=\"h-10 w-24\" />\n </div>\n\n {/* Table */}\n <div className=\"border rounded-lg overflow-hidden\">\n {/* Table header */}\n <div className=\"flex gap-4 p-4 bg-muted\">\n {headerKeys.map((key) => (\n <Skeleton key={key} className=\"h-4 flex-1\" />\n ))}\n </div>\n\n {/* Table rows */}\n {rowKeys.map((rowKey, rowIdx) => (\n <div key={rowKey} className=\"flex gap-4 p-4 border-t\">\n {cellKeys[rowIdx]?.map((cellKey) => (\n <Skeleton key={cellKey} className=\"h-4 flex-1\" />\n ))}\n </div>\n ))}\n </div>\n\n {/* Pagination */}\n <div className=\"flex justify-between items-center\">\n <Skeleton className=\"h-4 w-32\" />\n <div className=\"flex gap-2\">\n <Skeleton className=\"h-10 w-20\" />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AAI,WAAU,wBACb;AAAA,oBAAAA,MAAC,SAAI,WAAU,qCACb;AAAA,sBAAAA,MAAC,SACC;AAAA,wBAAAD,KAAC,QAAG,WAAU,sBAAqB,mBAAK;AAAA,QACxC,gBAAAA,KAAC,OAAE,WAAU,yBAAwB,+BAAiB;AAAA,SACxD;AAAA,MACA,gBAAAA,KAAC,UAAO,yBAAW;AAAA,OACrB;AAAA,IAEA,gBAAAA;AAAA,MAAC;AAAA;AAAA,QACC,MAAO,MAA4B,SAAS,CAAC;AAAA,QAC7C;AAAA,QACA;AAAA,QACA,cAAa;AAAA;AAAA,IACf;AAAA,IAEC,QACC,WAAW,QACX,KAAK,SACJ,KAAK,MAAiB,UAAU,SAC/B,gBAAAC,MAAC,SAAI,WAAU,qCACb;AAAA,sBAAAD;AAAA,QAAC;AAAA;AAAA,UACC,SAAQ;AAAA,UACR,UAAU,SAAS;AAAA,UACnB,SAAS,MAAM,QAAQ,CAAC,SAAS,OAAO,CAAC;AAAA,UAC1C;AAAA;AAAA,MAED;AAAA,MACA,gBAAAC,MAAC,UAAK,WAAU,iCAAgC;AAAA;AAAA,QAAM;AAAA,SAAK;AAAA,MAC3D,gBAAAD;AAAA,QAAC;AAAA;AAAA,UACC,SAAQ;AAAA,UACR,SAAS,MAAM,QAAQ,CAAC,SAAS,OAAO,CAAC;AAAA,UAC1C;AAAA;AAAA,MAED;AAAA,OACF;AAAA,KAEN;AAEJ;","names":["useState","jsx","_","jsx","jsxs","jsx","jsxs","useState"]}
|
|
1
|
+
{"version":3,"sources":["../../../src/components/iam/roles.tsx","../../../src/provider.tsx","../../../src/utils/cookie.ts","../../../src/components/shared/data-table.tsx","../../../src/components/skeletons/table-skeleton.tsx"],"sourcesContent":["'use client';\n\nimport { Badge, Button } from '@mesob/ui/components';\nimport { useLocale } from 'next-intl';\nimport { useState } from 'react';\nimport { useApi } from '../../provider';\nimport { DataTable, type DataTableColumn } from '../shared/data-table';\n\n// Role type from OpenAPI schema\ntype Role = {\n id: string;\n code: string;\n name: string | { am?: string; en?: string };\n description?: string | { am?: string; en?: string };\n createdAt: string;\n isSystem?: boolean;\n permissionCount?: number;\n};\n\nfunction getTranslation(\n value: string | { am?: string; en?: string } | null | undefined,\n locale: string,\n): string {\n if (!value) {\n return '';\n }\n if (typeof value === 'string') {\n return value;\n }\n if (typeof value === 'object') {\n return value[locale as 'am' | 'en'] ?? value.en ?? value.am ?? '';\n }\n return '';\n}\n\nexport function Roles() {\n const { hooks } = useApi();\n const locale = useLocale();\n const [page, setPage] = useState(1);\n const limit = 20;\n\n // Use openapi-react-query hooks\n const { data, isLoading, error } = hooks.useQuery('get', '/roles', {\n params: {\n query: {\n page: String(page),\n limit: String(limit),\n },\n },\n });\n\n const columns: DataTableColumn<Role>[] = [\n {\n key: 'name',\n header: 'Role',\n cell: (role) => (\n <div>\n <p className=\"font-medium\">{getTranslation(role.name, locale)}</p>\n <Badge variant=\"outline\" className=\"mt-1\">\n {role.code}\n </Badge>\n </div>\n ),\n },\n {\n key: 'access',\n header: 'Access',\n cell: (role) => (\n <div className=\"flex flex-wrap gap-2\">\n {role.isSystem ? <Badge>System</Badge> : null}\n <Badge variant=\"secondary\">\n {role.permissionCount ?? 0} permissions\n </Badge>\n </div>\n ),\n },\n {\n key: 'createdAt',\n header: 'Created',\n cell: (role) => (\n <p className=\"text-sm\">\n {new Date(role.createdAt).toLocaleDateString()}\n </p>\n ),\n },\n {\n key: 'actions',\n header: 'Actions',\n cell: (_role) => (\n <div className=\"flex gap-2\">\n <Button variant=\"outline\" size=\"sm\">\n Edit\n </Button>\n </div>\n ),\n },\n ];\n\n if (error) {\n return (\n <div className=\"p-6 text-center\">\n <p className=\"text-destructive\">Error loading roles</p>\n </div>\n );\n }\n\n return (\n <div className=\"w-full p-6 space-y-4\">\n <div className=\"flex justify-between items-center\">\n <div>\n <h1 className=\"text-3xl font-bold\">Roles</h1>\n <p className=\"text-muted-foreground\">\n Manage roles and assigned permissions\n </p>\n </div>\n <Button>Create Role</Button>\n </div>\n\n <DataTable\n data={(data as { roles: Role[] })?.roles || []}\n columns={columns}\n isLoading={isLoading}\n emptyMessage=\"No roles found\"\n />\n\n {data &&\n 'roles' in data &&\n data.roles &&\n (data.roles as Role[]).length >= limit && (\n <div className=\"flex justify-between items-center\">\n <Button\n variant=\"outline\"\n disabled={page === 1}\n onClick={() => setPage((prev) => prev - 1)}\n >\n Previous\n </Button>\n <span className=\"text-sm text-muted-foreground\">Page {page}</span>\n <Button\n variant=\"outline\"\n onClick={() => setPage((prev) => prev + 1)}\n >\n Next\n </Button>\n </div>\n )}\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","'use client';\n\nimport {\n Table,\n TableBody,\n TableCell,\n TableHead,\n TableHeader,\n TableRow,\n} from '@mesob/ui/components';\nimport type { ReactNode } from 'react';\nimport { TableSkeleton } from '../skeletons/table-skeleton';\n\nexport type DataTableColumn<T> = {\n key: string;\n header: string;\n cell: (row: T) => ReactNode;\n sortable?: boolean;\n};\n\ntype DataTableProps<T> = {\n data: T[];\n columns: DataTableColumn<T>[];\n isLoading?: boolean;\n onRowClick?: (row: T) => void;\n emptyMessage?: string;\n actions?: ReactNode;\n};\n\nexport function DataTable<T extends { id: string }>({\n data,\n columns,\n isLoading,\n onRowClick,\n emptyMessage = 'No data available',\n actions,\n}: DataTableProps<T>) {\n if (isLoading) {\n return <TableSkeleton columns={columns.length} rows={5} />;\n }\n\n if (data.length === 0) {\n return (\n <div className=\"flex flex-col items-center justify-center min-h-[400px] p-6\">\n <p className=\"text-muted-foreground\">{emptyMessage}</p>\n {actions && <div className=\"mt-4\">{actions}</div>}\n </div>\n );\n }\n\n return (\n <div className=\"w-full space-y-4\">\n {actions && <div className=\"flex justify-end\">{actions}</div>}\n\n <div className=\"border rounded-lg overflow-hidden\">\n <Table>\n <TableHeader>\n <TableRow>\n {columns.map((column) => (\n <TableHead key={column.key}>{column.header}</TableHead>\n ))}\n </TableRow>\n </TableHeader>\n <TableBody>\n {data.map((row) => (\n <TableRow\n key={row.id}\n onClick={() => onRowClick?.(row)}\n className={onRowClick ? 'cursor-pointer hover:bg-muted/50' : ''}\n >\n {columns.map((column) => (\n <TableCell key={`${row.id}-${column.key}`}>\n {column.cell(row)}\n </TableCell>\n ))}\n </TableRow>\n ))}\n </TableBody>\n </Table>\n </div>\n </div>\n );\n}\n","'use client';\n\nimport { Skeleton } from '@mesob/ui/components';\n\ntype TableSkeletonProps = {\n columns?: number;\n rows?: number;\n};\n\nexport function TableSkeleton({ columns = 5, rows = 10 }: TableSkeletonProps) {\n const headerKeys = Array.from({ length: columns }, (_, i) => `header-${i}`);\n const rowKeys = Array.from({ length: rows }, (_, i) => `row-${i}`);\n const cellKeys = Array.from({ length: rows }, (_, rowIdx) =>\n Array.from({ length: columns }, (_, colIdx) => `cell-${rowIdx}-${colIdx}`),\n );\n\n return (\n <div className=\"w-full space-y-4\">\n {/* Header */}\n <div className=\"flex justify-between items-center\">\n <Skeleton className=\"h-8 w-48\" />\n <Skeleton className=\"h-10 w-32\" />\n </div>\n\n {/* Search/filters */}\n <div className=\"flex gap-4\">\n <Skeleton className=\"h-10 flex-1 max-w-sm\" />\n <Skeleton className=\"h-10 w-24\" />\n <Skeleton className=\"h-10 w-24\" />\n </div>\n\n {/* Table */}\n <div className=\"border rounded-lg overflow-hidden\">\n {/* Table header */}\n <div className=\"flex gap-4 p-4 bg-muted\">\n {headerKeys.map((key) => (\n <Skeleton key={key} className=\"h-4 flex-1\" />\n ))}\n </div>\n\n {/* Table rows */}\n {rowKeys.map((rowKey, rowIdx) => (\n <div key={rowKey} className=\"flex gap-4 p-4 border-t\">\n {cellKeys[rowIdx]?.map((cellKey) => (\n <Skeleton key={cellKey} className=\"h-4 flex-1\" />\n ))}\n </div>\n ))}\n </div>\n\n {/* Pagination */}\n <div className=\"flex justify-between items-center\">\n <Skeleton className=\"h-4 w-32\" />\n <div className=\"flex gap-2\">\n <Skeleton className=\"h-10 w-20\" />\n <Skeleton className=\"h-10 w-20\" />\n </div>\n </div>\n </div>\n );\n}\n"],"mappings":";;;AAEA,SAAS,OAAO,cAAc;AAC9B,SAAS,iBAAiB;AAC1B,SAAS,YAAAA,iBAAgB;;;ACFzB,SAAS,aAAa,2BAA2B;AACjD,SAAS,iBAAiB;AAC1B,OAAO,uBAAuB;AAC9B,OAAO,kBAAkB;AAEzB,SAAS,eAAe,YAAY,SAAS,gBAAgB;;;ACL7D,IAAM,eACJ,OAAO,YAAY,e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;AAAA,MAAC;AAAA;AAAA,QACC,MAAO,MAA4B,SAAS,CAAC;AAAA,QAC7C;AAAA,QACA;AAAA,QACA,cAAa;AAAA;AAAA,IACf;AAAA,IAEC,QACC,WAAW,QACX,KAAK,SACJ,KAAK,MAAiB,UAAU,SAC/B,gBAAAC,MAAC,SAAI,WAAU,qCACb;AAAA,sBAAAD;AAAA,QAAC;AAAA;AAAA,UACC,SAAQ;AAAA,UACR,UAAU,SAAS;AAAA,UACnB,SAAS,MAAM,QAAQ,CAAC,SAAS,OAAO,CAAC;AAAA,UAC1C;AAAA;AAAA,MAED;AAAA,MACA,gBAAAC,MAAC,UAAK,WAAU,iCAAgC;AAAA;AAAA,QAAM;AAAA,SAAK;AAAA,MAC3D,gBAAAD;AAAA,QAAC;AAAA;AAAA,UACC,SAAQ;AAAA,UACR,SAAS,MAAM,QAAQ,CAAC,SAAS,OAAO,CAAC;AAAA,UAC1C;AAAA;AAAA,MAED;AAAA,OACF;AAAA,KAEN;AAEJ;","names":["useState","jsx","_","jsx","jsxs","jsx","jsxs","useState"]}
|
|
@@ -132,13 +132,7 @@ function Users() {
|
|
|
132
132
|
{
|
|
133
133
|
key: "fullName",
|
|
134
134
|
header: "Name",
|
|
135
|
-
cell: (user) => /* @__PURE__ */
|
|
136
|
-
/* @__PURE__ */ jsx4("p", { className: "font-medium", children: user.fullName }),
|
|
137
|
-
/* @__PURE__ */ jsxs3("p", { className: "text-sm text-muted-foreground", children: [
|
|
138
|
-
"@",
|
|
139
|
-
user.handle
|
|
140
|
-
] })
|
|
141
|
-
] })
|
|
135
|
+
cell: (user) => /* @__PURE__ */ jsx4("div", { children: /* @__PURE__ */ jsx4("p", { className: "font-medium", children: user.fullName }) })
|
|
142
136
|
},
|
|
143
137
|
{
|
|
144
138
|
key: "contact",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/components/iam/users.tsx","../../../src/provider.tsx","../../../src/utils/cookie.ts","../../../src/components/shared/data-table.tsx","../../../src/components/skeletons/table-skeleton.tsx"],"sourcesContent":["'use client';\n\nimport { Badge, Button } from '@mesob/ui/components';\nimport { useState } from 'react';\nimport { useApi } from '../../provider';\nimport { DataTable, type DataTableColumn } from '../shared/data-table';\n\n// User type from OpenAPI schema\ntype User = {\n id: string;\n fullName: string;\n email: string | null;\n phone: string | null;\n handle: string;\n emailVerified: boolean;\n phoneVerified: boolean;\n lastSignInAt: string | null;\n};\n\nexport function Users() {\n const { hooks } = useApi();\n const [page, setPage] = useState(1);\n const limit = 20;\n\n // Use openapi-react-query hooks\n const { data, isLoading, error } = hooks.useQuery('get', '/users', {\n params: {\n query: {\n page: String(page),\n limit: String(limit),\n },\n },\n });\n\n const columns: DataTableColumn<User>[] = [\n {\n key: 'fullName',\n header: 'Name',\n cell: (user) => (\n <div>\n <p className=\"font-medium\">{user.fullName}</p>\n <p className=\"text-sm text-muted-foreground\">@{user.handle}</p>\n </div>\n ),\n },\n {\n key: 'contact',\n header: 'Contact',\n cell: (user) => (\n <div className=\"space-y-1\">\n {user.email && (\n <div className=\"flex items-center gap-2\">\n <p className=\"text-sm\">{user.email}</p>\n {user.emailVerified && (\n <Badge variant=\"outline\" className=\"text-xs\">\n Verified\n </Badge>\n )}\n </div>\n )}\n {user.phone && (\n <div className=\"flex items-center gap-2\">\n <p className=\"text-sm\">{user.phone}</p>\n {user.phoneVerified && (\n <Badge variant=\"outline\" className=\"text-xs\">\n Verified\n </Badge>\n )}\n </div>\n )}\n </div>\n ),\n },\n {\n key: 'lastSignIn',\n header: 'Last Sign In',\n cell: (user) => (\n <p className=\"text-sm\">\n {user.lastSignInAt\n ? new Date(user.lastSignInAt).toLocaleDateString()\n : 'Never'}\n </p>\n ),\n },\n {\n key: 'actions',\n header: 'Actions',\n cell: (_user) => (\n <div className=\"flex gap-2\">\n <Button variant=\"outline\" size=\"sm\">\n View\n </Button>\n <Button variant=\"outline\" size=\"sm\">\n Edit\n </Button>\n </div>\n ),\n },\n ];\n\n if (error) {\n return (\n <div className=\"p-6 text-center\">\n <p className=\"text-destructive\">Error loading users</p>\n </div>\n );\n }\n\n return (\n <div className=\"w-full p-6 space-y-4\">\n <div className=\"flex justify-between items-center\">\n <div>\n <h1 className=\"text-3xl font-bold\">Users</h1>\n <p className=\"text-muted-foreground\">Manage user accounts</p>\n </div>\n <Button>Create User</Button>\n </div>\n\n <DataTable\n data={(data as { users: User[] })?.users || []}\n columns={columns}\n isLoading={isLoading}\n emptyMessage=\"No users found\"\n />\n\n {data &&\n 'users' in data &&\n data.users &&\n (data.users as User[]).length >= limit && (\n <div className=\"flex justify-between items-center\">\n <Button\n variant=\"outline\"\n disabled={page === 1}\n onClick={() => setPage((prev) => prev - 1)}\n >\n Previous\n </Button>\n <span className=\"text-sm text-muted-foreground\">Page {page}</span>\n <Button\n variant=\"outline\"\n onClick={() => setPage((prev) => prev + 1)}\n >\n Next\n </Button>\n </div>\n )}\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","'use client';\n\nimport {\n Table,\n TableBody,\n TableCell,\n TableHead,\n TableHeader,\n TableRow,\n} from '@mesob/ui/components';\nimport type { ReactNode } from 'react';\nimport { TableSkeleton } from '../skeletons/table-skeleton';\n\nexport type DataTableColumn<T> = {\n key: string;\n header: string;\n cell: (row: T) => ReactNode;\n sortable?: boolean;\n};\n\ntype DataTableProps<T> = {\n data: T[];\n columns: DataTableColumn<T>[];\n isLoading?: boolean;\n onRowClick?: (row: T) => void;\n emptyMessage?: string;\n actions?: ReactNode;\n};\n\nexport function DataTable<T extends { id: string }>({\n data,\n columns,\n isLoading,\n onRowClick,\n emptyMessage = 'No data available',\n actions,\n}: DataTableProps<T>) {\n if (isLoading) {\n return <TableSkeleton columns={columns.length} rows={5} />;\n }\n\n if (data.length === 0) {\n return (\n <div className=\"flex flex-col items-center justify-center min-h-[400px] p-6\">\n <p className=\"text-muted-foreground\">{emptyMessage}</p>\n {actions && <div className=\"mt-4\">{actions}</div>}\n </div>\n );\n }\n\n return (\n <div className=\"w-full space-y-4\">\n {actions && <div className=\"flex justify-end\">{actions}</div>}\n\n <div className=\"border rounded-lg overflow-hidden\">\n <Table>\n <TableHeader>\n <TableRow>\n {columns.map((column) => (\n <TableHead key={column.key}>{column.header}</TableHead>\n ))}\n </TableRow>\n </TableHeader>\n <TableBody>\n {data.map((row) => (\n <TableRow\n key={row.id}\n onClick={() => onRowClick?.(row)}\n className={onRowClick ? 'cursor-pointer hover:bg-muted/50' : ''}\n >\n {columns.map((column) => (\n <TableCell key={`${row.id}-${column.key}`}>\n {column.cell(row)}\n </TableCell>\n ))}\n </TableRow>\n ))}\n </TableBody>\n </Table>\n </div>\n </div>\n );\n}\n","'use client';\n\nimport { Skeleton } from '@mesob/ui/components';\n\ntype TableSkeletonProps = {\n columns?: number;\n rows?: number;\n};\n\nexport function TableSkeleton({ columns = 5, rows = 10 }: TableSkeletonProps) {\n const headerKeys = Array.from({ length: columns }, (_, i) => `header-${i}`);\n const rowKeys = Array.from({ length: rows }, (_, i) => `row-${i}`);\n const cellKeys = Array.from({ length: rows }, (_, rowIdx) =>\n Array.from({ length: columns }, (_, colIdx) => `cell-${rowIdx}-${colIdx}`),\n );\n\n return (\n <div className=\"w-full space-y-4\">\n {/* Header */}\n <div className=\"flex justify-between items-center\">\n <Skeleton className=\"h-8 w-48\" />\n <Skeleton className=\"h-10 w-32\" />\n </div>\n\n {/* Search/filters */}\n <div className=\"flex gap-4\">\n <Skeleton className=\"h-10 flex-1 max-w-sm\" />\n <Skeleton className=\"h-10 w-24\" />\n <Skeleton className=\"h-10 w-24\" />\n </div>\n\n {/* Table */}\n <div className=\"border rounded-lg overflow-hidden\">\n {/* Table header */}\n <div className=\"flex gap-4 p-4 bg-muted\">\n {headerKeys.map((key) => (\n <Skeleton key={key} className=\"h-4 flex-1\" />\n ))}\n </div>\n\n {/* Table rows */}\n {rowKeys.map((rowKey, rowIdx) => (\n <div key={rowKey} className=\"flex gap-4 p-4 border-t\">\n {cellKeys[rowIdx]?.map((cellKey) => (\n <Skeleton key={cellKey} className=\"h-4 flex-1\" />\n ))}\n </div>\n ))}\n </div>\n\n {/* Pagination */}\n <div className=\"flex justify-between items-center\">\n <Skeleton className=\"h-4 w-32\" />\n <div className=\"flex gap-2\">\n <Skeleton className=\"h-10 w-20\" />\n <Skeleton className=\"h-10 w-20\" />\n </div>\n </div>\n </div>\n );\n}\n"],"mappings":";;;AAEA,SAAS,OAAO,cAAc;AAC9B,SAAS,YAAAA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ACb;AAAA,oBAAAA,MAAC,SAAI,WAAU,qCACb;AAAA,sBAAAA,MAAC,SACC;AAAA,wBAAAD,KAAC,QAAG,WAAU,sBAAqB,mBAAK;AAAA,QACxC,gBAAAA,KAAC,OAAE,WAAU,yBAAwB,kCAAoB;AAAA,SAC3D;AAAA,MACA,gBAAAA,KAAC,UAAO,yBAAW;AAAA,OACrB;AAAA,IAEA,gBAAAA;AAAA,MAAC;AAAA;AAAA,QACC,MAAO,MAA4B,SAAS,CAAC;AAAA,QAC7C;AAAA,QACA;AAAA,QACA,cAAa;AAAA;AAAA,IACf;AAAA,IAEC,QACC,WAAW,QACX,KAAK,SACJ,KAAK,MAAiB,UAAU,SAC/B,gBAAAC,MAAC,SAAI,WAAU,qCACb;AAAA,sBAAAD;AAAA,QAAC;AAAA;AAAA,UACC,SAAQ;AAAA,UACR,UAAU,SAAS;AAAA,UACnB,SAAS,MAAM,QAAQ,CAAC,SAAS,OAAO,CAAC;AAAA,UAC1C;AAAA;AAAA,MAED;AAAA,MACA,gBAAAC,MAAC,UAAK,WAAU,iCAAgC;AAAA;AAAA,QAAM;AAAA,SAAK;AAAA,MAC3D,gBAAAD;AAAA,QAAC;AAAA;AAAA,UACC,SAAQ;AAAA,UACR,SAAS,MAAM,QAAQ,CAAC,SAAS,OAAO,CAAC;AAAA,UAC1C;AAAA;AAAA,MAED;AAAA,OACF;AAAA,KAEN;AAEJ;","names":["useState","jsx","_","jsx","jsxs","jsx","jsxs","useState"]}
|
|
1
|
+
{"version":3,"sources":["../../../src/components/iam/users.tsx","../../../src/provider.tsx","../../../src/utils/cookie.ts","../../../src/components/shared/data-table.tsx","../../../src/components/skeletons/table-skeleton.tsx"],"sourcesContent":["'use client';\n\nimport { Badge, Button } from '@mesob/ui/components';\nimport { useState } from 'react';\nimport { useApi } from '../../provider';\nimport { DataTable, type DataTableColumn } from '../shared/data-table';\n\n// User type from OpenAPI schema\ntype User = {\n id: string;\n fullName: string;\n email: string | null;\n phone: string | null;\n handle: string;\n emailVerified: boolean;\n phoneVerified: boolean;\n lastSignInAt: string | null;\n};\n\nexport function Users() {\n const { hooks } = useApi();\n const [page, setPage] = useState(1);\n const limit = 20;\n\n // Use openapi-react-query hooks\n const { data, isLoading, error } = hooks.useQuery('get', '/users', {\n params: {\n query: {\n page: String(page),\n limit: String(limit),\n },\n },\n });\n\n const columns: DataTableColumn<User>[] = [\n {\n key: 'fullName',\n header: 'Name',\n cell: (user) => (\n <div>\n <p className=\"font-medium\">{user.fullName}</p>\n </div>\n ),\n },\n {\n key: 'contact',\n header: 'Contact',\n cell: (user) => (\n <div className=\"space-y-1\">\n {user.email && (\n <div className=\"flex items-center gap-2\">\n <p className=\"text-sm\">{user.email}</p>\n {user.emailVerified && (\n <Badge variant=\"outline\" className=\"text-xs\">\n Verified\n </Badge>\n )}\n </div>\n )}\n {user.phone && (\n <div className=\"flex items-center gap-2\">\n <p className=\"text-sm\">{user.phone}</p>\n {user.phoneVerified && (\n <Badge variant=\"outline\" className=\"text-xs\">\n Verified\n </Badge>\n )}\n </div>\n )}\n </div>\n ),\n },\n {\n key: 'lastSignIn',\n header: 'Last Sign In',\n cell: (user) => (\n <p className=\"text-sm\">\n {user.lastSignInAt\n ? new Date(user.lastSignInAt).toLocaleDateString()\n : 'Never'}\n </p>\n ),\n },\n {\n key: 'actions',\n header: 'Actions',\n cell: (_user) => (\n <div className=\"flex gap-2\">\n <Button variant=\"outline\" size=\"sm\">\n View\n </Button>\n <Button variant=\"outline\" size=\"sm\">\n Edit\n </Button>\n </div>\n ),\n },\n ];\n\n if (error) {\n return (\n <div className=\"p-6 text-center\">\n <p className=\"text-destructive\">Error loading users</p>\n </div>\n );\n }\n\n return (\n <div className=\"w-full p-6 space-y-4\">\n <div className=\"flex justify-between items-center\">\n <div>\n <h1 className=\"text-3xl font-bold\">Users</h1>\n <p className=\"text-muted-foreground\">Manage user accounts</p>\n </div>\n <Button>Create User</Button>\n </div>\n\n <DataTable\n data={(data as { users: User[] })?.users || []}\n columns={columns}\n isLoading={isLoading}\n emptyMessage=\"No users found\"\n />\n\n {data &&\n 'users' in data &&\n data.users &&\n (data.users as User[]).length >= limit && (\n <div className=\"flex justify-between items-center\">\n <Button\n variant=\"outline\"\n disabled={page === 1}\n onClick={() => setPage((prev) => prev - 1)}\n >\n Previous\n </Button>\n <span className=\"text-sm text-muted-foreground\">Page {page}</span>\n <Button\n variant=\"outline\"\n onClick={() => setPage((prev) => prev + 1)}\n >\n Next\n </Button>\n </div>\n )}\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","'use client';\n\nimport {\n Table,\n TableBody,\n TableCell,\n TableHead,\n TableHeader,\n TableRow,\n} from '@mesob/ui/components';\nimport type { ReactNode } from 'react';\nimport { TableSkeleton } from '../skeletons/table-skeleton';\n\nexport type DataTableColumn<T> = {\n key: string;\n header: string;\n cell: (row: T) => ReactNode;\n sortable?: boolean;\n};\n\ntype DataTableProps<T> = {\n data: T[];\n columns: DataTableColumn<T>[];\n isLoading?: boolean;\n onRowClick?: (row: T) => void;\n emptyMessage?: string;\n actions?: ReactNode;\n};\n\nexport function DataTable<T extends { id: string }>({\n data,\n columns,\n isLoading,\n onRowClick,\n emptyMessage = 'No data available',\n actions,\n}: DataTableProps<T>) {\n if (isLoading) {\n return <TableSkeleton columns={columns.length} rows={5} />;\n }\n\n if (data.length === 0) {\n return (\n <div className=\"flex flex-col items-center justify-center min-h-[400px] p-6\">\n <p className=\"text-muted-foreground\">{emptyMessage}</p>\n {actions && <div className=\"mt-4\">{actions}</div>}\n </div>\n );\n }\n\n return (\n <div className=\"w-full space-y-4\">\n {actions && <div className=\"flex justify-end\">{actions}</div>}\n\n <div className=\"border rounded-lg overflow-hidden\">\n <Table>\n <TableHeader>\n <TableRow>\n {columns.map((column) => (\n <TableHead key={column.key}>{column.header}</TableHead>\n ))}\n </TableRow>\n </TableHeader>\n <TableBody>\n {data.map((row) => (\n <TableRow\n key={row.id}\n onClick={() => onRowClick?.(row)}\n className={onRowClick ? 'cursor-pointer hover:bg-muted/50' : ''}\n >\n {columns.map((column) => (\n <TableCell key={`${row.id}-${column.key}`}>\n {column.cell(row)}\n </TableCell>\n ))}\n </TableRow>\n ))}\n </TableBody>\n </Table>\n </div>\n </div>\n );\n}\n","'use client';\n\nimport { Skeleton } from '@mesob/ui/components';\n\ntype TableSkeletonProps = {\n columns?: number;\n rows?: number;\n};\n\nexport function TableSkeleton({ columns = 5, rows = 10 }: TableSkeletonProps) {\n const headerKeys = Array.from({ length: columns }, (_, i) => `header-${i}`);\n const rowKeys = Array.from({ length: rows }, (_, i) => `row-${i}`);\n const cellKeys = Array.from({ length: rows }, (_, rowIdx) =>\n Array.from({ length: columns }, (_, colIdx) => `cell-${rowIdx}-${colIdx}`),\n );\n\n return (\n <div className=\"w-full space-y-4\">\n {/* Header */}\n <div className=\"flex justify-between items-center\">\n <Skeleton className=\"h-8 w-48\" />\n <Skeleton className=\"h-10 w-32\" />\n </div>\n\n {/* Search/filters */}\n <div className=\"flex gap-4\">\n <Skeleton className=\"h-10 flex-1 max-w-sm\" />\n <Skeleton className=\"h-10 w-24\" />\n <Skeleton className=\"h-10 w-24\" />\n </div>\n\n {/* Table */}\n <div className=\"border rounded-lg overflow-hidden\">\n {/* Table header */}\n <div className=\"flex gap-4 p-4 bg-muted\">\n {headerKeys.map((key) => (\n <Skeleton key={key} className=\"h-4 flex-1\" />\n ))}\n </div>\n\n {/* Table rows */}\n {rowKeys.map((rowKey, rowIdx) => (\n <div key={rowKey} className=\"flex gap-4 p-4 border-t\">\n {cellKeys[rowIdx]?.map((cellKey) => (\n <Skeleton key={cellKey} className=\"h-4 flex-1\" />\n ))}\n </div>\n ))}\n </div>\n\n {/* Pagination */}\n <div className=\"flex justify-between items-center\">\n <Skeleton className=\"h-4 w-32\" />\n <div className=\"flex gap-2\">\n <Skeleton className=\"h-10 w-20\" />\n <Skeleton className=\"h-10 w-20\" />\n </div>\n </div>\n </div>\n );\n}\n"],"mappings":";;;AAEA,SAAS,OAAO,cAAc;AAC9B,SAAS,YAAAA,iBAAgB;;;ACDzB,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,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a;AAAA;AAAA,IACf;AAAA,IAEC,QACC,WAAW,QACX,KAAK,SACJ,KAAK,MAAiB,UAAU,SAC/B,gBAAAC,MAAC,SAAI,WAAU,qCACb;AAAA,sBAAAD;AAAA,QAAC;AAAA;AAAA,UACC,SAAQ;AAAA,UACR,UAAU,SAAS;AAAA,UACnB,SAAS,MAAM,QAAQ,CAAC,SAAS,OAAO,CAAC;AAAA,UAC1C;AAAA;AAAA,MAED;AAAA,MACA,gBAAAC,MAAC,UAAK,WAAU,iCAAgC;AAAA;AAAA,QAAM;AAAA,SAAK;AAAA,MAC3D,gBAAAD;AAAA,QAAC;AAAA;AAAA,UACC,SAAQ;AAAA,UACR,SAAS,MAAM,QAAQ,CAAC,SAAS,OAAO,CAAC;AAAA,UAC1C;AAAA;AAAA,MAED;AAAA,OACF;AAAA,KAEN;AAEJ;","names":["useState","jsx","_","jsx","jsxs","jsx","jsxs","useState"]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
3
|
// src/components/profile/account.tsx
|
|
4
|
-
import { Separator } from "@mesob/ui/components";
|
|
4
|
+
import { Badge as Badge2, Card, CardContent, Separator } from "@mesob/ui/components";
|
|
5
5
|
|
|
6
6
|
// src/provider.tsx
|
|
7
7
|
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
|
@@ -33,30 +33,121 @@ function useSession() {
|
|
|
33
33
|
return context;
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
// src/components/profile/
|
|
36
|
+
// src/components/profile/change-profile.tsx
|
|
37
|
+
import {
|
|
38
|
+
Avatar,
|
|
39
|
+
AvatarFallback,
|
|
40
|
+
AvatarImage,
|
|
41
|
+
Badge,
|
|
42
|
+
Button
|
|
43
|
+
} from "@mesob/ui/components";
|
|
44
|
+
import { useState as useState2 } from "react";
|
|
37
45
|
import { jsx as jsx2, jsxs } from "react/jsx-runtime";
|
|
46
|
+
var ChangeProfile = ({ user }) => {
|
|
47
|
+
const [isEditing, setIsEditing] = useState2(false);
|
|
48
|
+
const initials = user.fullName?.split(" ").map((part) => part[0]).join("").toUpperCase().slice(0, 2) || "U";
|
|
49
|
+
return /* @__PURE__ */ jsxs("div", { className: "w-full rounded-[1.5rem] border border-border/60 bg-background/80 p-5 shadow-sm backdrop-blur", children: [
|
|
50
|
+
/* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-4 md:flex-row md:items-center md:justify-between", children: [
|
|
51
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-4", children: [
|
|
52
|
+
/* @__PURE__ */ jsxs(Avatar, { className: "h-14 w-14 ring-4 ring-primary/10", children: [
|
|
53
|
+
/* @__PURE__ */ jsx2(AvatarImage, { src: user.image || "", alt: user.fullName || "" }),
|
|
54
|
+
/* @__PURE__ */ jsx2(AvatarFallback, { children: initials })
|
|
55
|
+
] }),
|
|
56
|
+
/* @__PURE__ */ jsxs("div", { className: "space-y-1", children: [
|
|
57
|
+
/* @__PURE__ */ jsx2("div", { className: "text-base font-semibold", children: user.fullName }),
|
|
58
|
+
/* @__PURE__ */ jsxs("div", { className: "flex flex-wrap gap-2 text-xs text-muted-foreground", children: [
|
|
59
|
+
/* @__PURE__ */ jsx2(Badge, { variant: "outline", children: user.emailVerified ? "Email verified" : "Email unverified" }),
|
|
60
|
+
/* @__PURE__ */ jsx2(Badge, { variant: "outline", children: user.phoneVerified ? "Phone verified" : "Phone unverified" })
|
|
61
|
+
] })
|
|
62
|
+
] })
|
|
63
|
+
] }),
|
|
64
|
+
/* @__PURE__ */ jsx2(
|
|
65
|
+
Button,
|
|
66
|
+
{
|
|
67
|
+
variant: "secondary",
|
|
68
|
+
className: "rounded-full px-5 text-primary hover:text-primary/80",
|
|
69
|
+
onClick: () => setIsEditing((v) => !v),
|
|
70
|
+
children: isEditing ? "Hide editor" : "Update profile"
|
|
71
|
+
}
|
|
72
|
+
)
|
|
73
|
+
] }),
|
|
74
|
+
isEditing && /* @__PURE__ */ jsx2("div", { className: "mt-4 rounded-2xl border border-dashed border-border bg-muted/30 px-4 py-3 text-sm text-muted-foreground", children: "Profile editing is not wired yet. Contact and password flows below are live." })
|
|
75
|
+
] });
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
// src/components/profile/account.tsx
|
|
79
|
+
import { jsx as jsx3, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
38
80
|
function Account() {
|
|
39
81
|
const { user, isAuthenticated } = useSession();
|
|
40
82
|
if (!(isAuthenticated && user)) {
|
|
41
|
-
return /* @__PURE__ */
|
|
83
|
+
return /* @__PURE__ */ jsx3("div", { className: "rounded-[1.75rem] border border-dashed border-border bg-muted/30 p-8 text-sm text-muted-foreground", children: "Sign in required." });
|
|
42
84
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
85
|
+
const contactItems = [
|
|
86
|
+
{
|
|
87
|
+
label: "Email",
|
|
88
|
+
value: user.email ?? "No email address",
|
|
89
|
+
status: user.emailVerified ? "Verified" : "Needs verification"
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
label: "Phone",
|
|
93
|
+
value: user.phone ?? "No phone number",
|
|
94
|
+
status: user.phoneVerified ? "Verified" : "Needs verification"
|
|
95
|
+
}
|
|
96
|
+
];
|
|
97
|
+
return /* @__PURE__ */ jsxs2("div", { className: "mx-auto flex w-full max-w-6xl flex-col gap-6", children: [
|
|
98
|
+
/* @__PURE__ */ jsxs2("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", children: [
|
|
99
|
+
/* @__PURE__ */ jsx3("div", { className: "absolute inset-y-0 right-0 w-1/3 bg-[radial-gradient(circle_at_top,_hsl(var(--primary)/0.16),_transparent_60%)]" }),
|
|
100
|
+
/* @__PURE__ */ jsxs2("div", { className: "relative flex flex-col gap-5", children: [
|
|
101
|
+
/* @__PURE__ */ jsxs2("div", { className: "flex flex-wrap items-center gap-2", children: [
|
|
102
|
+
/* @__PURE__ */ jsx3(Badge2, { variant: "outline", children: "Profile console" }),
|
|
103
|
+
/* @__PURE__ */ jsx3(Badge2, { variant: "secondary", children: "Live session data" })
|
|
104
|
+
] }),
|
|
105
|
+
/* @__PURE__ */ jsxs2("div", { className: "max-w-2xl space-y-2", children: [
|
|
106
|
+
/* @__PURE__ */ jsx3("h2", { className: "text-2xl font-semibold tracking-tight", children: "Account details, contact state, and verification status." }),
|
|
107
|
+
/* @__PURE__ */ jsx3("p", { className: "text-sm text-muted-foreground", children: "Keep the identity surface minimal here. Contact updates and sensitive changes stay in security." })
|
|
108
|
+
] }),
|
|
109
|
+
/* @__PURE__ */ jsx3(ChangeProfile, { user })
|
|
59
110
|
] })
|
|
111
|
+
] }),
|
|
112
|
+
/* @__PURE__ */ jsxs2("div", { className: "grid gap-4 lg:grid-cols-[1.5fr_0.9fr]", children: [
|
|
113
|
+
/* @__PURE__ */ jsx3(Card, { className: "rounded-[1.75rem] border-border/60 shadow-sm", children: /* @__PURE__ */ jsxs2(CardContent, { className: "space-y-5 p-6", children: [
|
|
114
|
+
/* @__PURE__ */ jsxs2("div", { className: "space-y-1", children: [
|
|
115
|
+
/* @__PURE__ */ jsx3("div", { className: "text-sm font-medium text-muted-foreground", children: "Contact channels" }),
|
|
116
|
+
/* @__PURE__ */ jsx3("div", { className: "text-lg font-semibold", children: "Primary profile data" })
|
|
117
|
+
] }),
|
|
118
|
+
/* @__PURE__ */ jsx3(Separator, {}),
|
|
119
|
+
/* @__PURE__ */ jsx3("div", { className: "space-y-4", children: contactItems.map((item) => /* @__PURE__ */ jsxs2(
|
|
120
|
+
"div",
|
|
121
|
+
{
|
|
122
|
+
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",
|
|
123
|
+
children: [
|
|
124
|
+
/* @__PURE__ */ jsxs2("div", { className: "space-y-1", children: [
|
|
125
|
+
/* @__PURE__ */ jsx3("div", { className: "text-sm font-medium", children: item.label }),
|
|
126
|
+
/* @__PURE__ */ jsx3("div", { className: "text-sm text-muted-foreground", children: item.value })
|
|
127
|
+
] }),
|
|
128
|
+
/* @__PURE__ */ jsx3(Badge2, { variant: "outline", children: item.status })
|
|
129
|
+
]
|
|
130
|
+
},
|
|
131
|
+
item.label
|
|
132
|
+
)) })
|
|
133
|
+
] }) }),
|
|
134
|
+
/* @__PURE__ */ jsx3(Card, { className: "rounded-[1.75rem] border-border/60 shadow-sm", children: /* @__PURE__ */ jsxs2(CardContent, { className: "space-y-5 p-6", children: [
|
|
135
|
+
/* @__PURE__ */ jsxs2("div", { className: "space-y-1", children: [
|
|
136
|
+
/* @__PURE__ */ jsx3("div", { className: "text-sm font-medium text-muted-foreground", children: "Snapshot" }),
|
|
137
|
+
/* @__PURE__ */ jsx3("div", { className: "text-lg font-semibold", children: "Session-facing identity" })
|
|
138
|
+
] }),
|
|
139
|
+
/* @__PURE__ */ jsx3(Separator, {}),
|
|
140
|
+
/* @__PURE__ */ jsxs2("div", { className: "grid gap-3", children: [
|
|
141
|
+
/* @__PURE__ */ jsxs2("div", { className: "rounded-2xl bg-primary/[0.06] p-4", children: [
|
|
142
|
+
/* @__PURE__ */ jsx3("div", { className: "text-xs uppercase tracking-[0.18em] text-muted-foreground", children: "Full name" }),
|
|
143
|
+
/* @__PURE__ */ jsx3("div", { className: "mt-2 text-base font-semibold", children: user.fullName })
|
|
144
|
+
] }),
|
|
145
|
+
/* @__PURE__ */ jsxs2("div", { className: "rounded-2xl bg-muted/25 p-4", children: [
|
|
146
|
+
/* @__PURE__ */ jsx3("div", { className: "text-xs uppercase tracking-[0.18em] text-muted-foreground", children: "Last sign in" }),
|
|
147
|
+
/* @__PURE__ */ jsx3("div", { className: "mt-2 text-base font-semibold", children: user.lastSignInAt ? new Date(user.lastSignInAt).toLocaleString() : "No activity recorded" })
|
|
148
|
+
] })
|
|
149
|
+
] })
|
|
150
|
+
] }) })
|
|
60
151
|
] })
|
|
61
152
|
] });
|
|
62
153
|
}
|