@mesob/auth-react 0.3.4 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (142) hide show
  1. package/dist/components/auth/auth-layout.d.ts +1 -1
  2. package/dist/components/auth/auth-layout.js +10 -2
  3. package/dist/components/auth/auth-layout.js.map +1 -1
  4. package/dist/components/auth/countdown.js +8 -6
  5. package/dist/components/auth/countdown.js.map +1 -1
  6. package/dist/components/auth/forgot-password.js +21 -19
  7. package/dist/components/auth/forgot-password.js.map +1 -1
  8. package/dist/components/auth/reset-password-form.js +22 -21
  9. package/dist/components/auth/reset-password-form.js.map +1 -1
  10. package/dist/components/auth/set-password.d.ts +9 -0
  11. package/dist/components/auth/set-password.js +527 -0
  12. package/dist/components/auth/set-password.js.map +1 -0
  13. package/dist/components/auth/sign-in.js +45 -26
  14. package/dist/components/auth/sign-in.js.map +1 -1
  15. package/dist/components/auth/sign-up.js +25 -29
  16. package/dist/components/auth/sign-up.js.map +1 -1
  17. package/dist/components/auth/verification-form.js +24 -27
  18. package/dist/components/auth/verification-form.js.map +1 -1
  19. package/dist/components/auth/verify-email.js +40 -31
  20. package/dist/components/auth/verify-email.js.map +1 -1
  21. package/dist/components/auth/verify-phone.js +40 -31
  22. package/dist/components/auth/verify-phone.js.map +1 -1
  23. package/dist/components/authorization/deny.d.ts +11 -0
  24. package/dist/components/authorization/deny.js +52 -0
  25. package/dist/components/authorization/deny.js.map +1 -0
  26. package/dist/components/authorization/grant.d.ts +12 -0
  27. package/dist/components/authorization/grant.js +57 -0
  28. package/dist/components/authorization/grant.js.map +1 -0
  29. package/dist/components/iam/permission-selector.d.ts +19 -0
  30. package/dist/components/iam/permission-selector.js +122 -0
  31. package/dist/components/iam/permission-selector.js.map +1 -0
  32. package/dist/components/iam/permissions.js +21 -33
  33. package/dist/components/iam/permissions.js.map +1 -1
  34. package/dist/components/iam/role-detail-layout.d.ts +11 -0
  35. package/dist/components/iam/role-detail-layout.js +137 -0
  36. package/dist/components/iam/role-detail-layout.js.map +1 -0
  37. package/dist/components/iam/role-detail-page.d.ts +9 -0
  38. package/dist/components/iam/role-detail-page.js +229 -0
  39. package/dist/components/iam/role-detail-page.js.map +1 -0
  40. package/dist/components/iam/role-permissions-page.d.ts +8 -0
  41. package/dist/components/iam/role-permissions-page.js +397 -0
  42. package/dist/components/iam/role-permissions-page.js.map +1 -0
  43. package/dist/components/iam/roles.js +20 -10
  44. package/dist/components/iam/roles.js.map +1 -1
  45. package/dist/components/iam/tenants.js +9 -2
  46. package/dist/components/iam/tenants.js.map +1 -1
  47. package/dist/components/iam/users.js +10 -9
  48. package/dist/components/iam/users.js.map +1 -1
  49. package/dist/components/profile/account.js +110 -19
  50. package/dist/components/profile/account.js.map +1 -1
  51. package/dist/components/profile/change-email-form.js +26 -29
  52. package/dist/components/profile/change-email-form.js.map +1 -1
  53. package/dist/components/profile/change-phone-form.js +26 -29
  54. package/dist/components/profile/change-phone-form.js.map +1 -1
  55. package/dist/components/profile/change-profile.d.ts +2 -1
  56. package/dist/components/profile/change-profile.js +16 -8
  57. package/dist/components/profile/change-profile.js.map +1 -1
  58. package/dist/components/profile/otp-verification-modal.js +24 -27
  59. package/dist/components/profile/otp-verification-modal.js.map +1 -1
  60. package/dist/components/profile/security.js +88 -57
  61. package/dist/components/profile/security.js.map +1 -1
  62. package/dist/components/profile/verify-change-email-form.js +24 -27
  63. package/dist/components/profile/verify-change-email-form.js.map +1 -1
  64. package/dist/components/profile/verify-change-phone-form.js +24 -27
  65. package/dist/components/profile/verify-change-phone-form.js.map +1 -1
  66. package/dist/index.d.ts +9 -1
  67. package/dist/index.js +1897 -821
  68. package/dist/index.js.map +1 -1
  69. package/dist/pages/auth/forgot-password.d.ts +7 -0
  70. package/dist/pages/auth/forgot-password.js +784 -0
  71. package/dist/pages/auth/forgot-password.js.map +1 -0
  72. package/dist/pages/auth/layout.d.ts +8 -0
  73. package/dist/pages/auth/layout.js +562 -0
  74. package/dist/pages/auth/layout.js.map +1 -0
  75. package/dist/pages/auth/reset-password.d.ts +10 -0
  76. package/dist/pages/auth/reset-password.js +913 -0
  77. package/dist/pages/auth/reset-password.js.map +1 -0
  78. package/dist/pages/auth/set-password.d.ts +10 -0
  79. package/dist/pages/auth/set-password.js +946 -0
  80. package/dist/pages/auth/set-password.js.map +1 -0
  81. package/dist/pages/auth/sign-in.d.ts +10 -0
  82. package/dist/pages/auth/sign-in.js +984 -0
  83. package/dist/pages/auth/sign-in.js.map +1 -0
  84. package/dist/pages/auth/sign-up.d.ts +10 -0
  85. package/dist/pages/auth/sign-up.js +940 -0
  86. package/dist/pages/auth/sign-up.js.map +1 -0
  87. package/dist/pages/auth/verify-email.d.ts +10 -0
  88. package/dist/pages/auth/verify-email.js +950 -0
  89. package/dist/pages/auth/verify-email.js.map +1 -0
  90. package/dist/pages/auth/verify-phone.d.ts +10 -0
  91. package/dist/pages/auth/verify-phone.js +964 -0
  92. package/dist/pages/auth/verify-phone.js.map +1 -0
  93. package/dist/pages/iam/permissions.d.ts +5 -0
  94. package/dist/pages/iam/permissions.js +308 -0
  95. package/dist/pages/iam/permissions.js.map +1 -0
  96. package/dist/pages/iam/role-detail-layout.d.ts +12 -0
  97. package/dist/pages/iam/role-detail-layout.js +145 -0
  98. package/dist/pages/iam/role-detail-layout.js.map +1 -0
  99. package/dist/pages/iam/role-detail.d.ts +12 -0
  100. package/dist/pages/iam/role-detail.js +241 -0
  101. package/dist/pages/iam/role-detail.js.map +1 -0
  102. package/dist/pages/iam/role-permissions.d.ts +12 -0
  103. package/dist/pages/iam/role-permissions.js +409 -0
  104. package/dist/pages/iam/role-permissions.js.map +1 -0
  105. package/dist/pages/iam/role-users.d.ts +12 -0
  106. package/dist/pages/iam/role-users.js +825 -0
  107. package/dist/pages/iam/role-users.js.map +1 -0
  108. package/dist/pages/iam/roles.d.ts +5 -0
  109. package/dist/pages/iam/roles.js +684 -0
  110. package/dist/pages/iam/roles.js.map +1 -0
  111. package/dist/pages/iam/sessions.d.ts +5 -0
  112. package/dist/pages/iam/sessions.js +315 -0
  113. package/dist/pages/iam/sessions.js.map +1 -0
  114. package/dist/pages/iam/tenant-detail.d.ts +10 -0
  115. package/dist/pages/iam/tenant-detail.js +186 -0
  116. package/dist/pages/iam/tenant-detail.js.map +1 -0
  117. package/dist/pages/iam/tenants.d.ts +5 -0
  118. package/dist/pages/iam/tenants.js +610 -0
  119. package/dist/pages/iam/tenants.js.map +1 -0
  120. package/dist/pages/iam/user-activity.d.ts +10 -0
  121. package/dist/pages/iam/user-activity.js +850 -0
  122. package/dist/pages/iam/user-activity.js.map +1 -0
  123. package/dist/pages/iam/user-detail-layout.d.ts +12 -0
  124. package/dist/pages/iam/user-detail-layout.js +106 -0
  125. package/dist/pages/iam/user-detail-layout.js.map +1 -0
  126. package/dist/pages/iam/user-detail.d.ts +10 -0
  127. package/dist/pages/iam/user-detail.js +102 -0
  128. package/dist/pages/iam/user-detail.js.map +1 -0
  129. package/dist/pages/iam/users.d.ts +5 -0
  130. package/dist/pages/iam/users.js +1275 -0
  131. package/dist/pages/iam/users.js.map +1 -0
  132. package/dist/pages/profile/account.d.ts +5 -0
  133. package/dist/pages/profile/account.js +182 -0
  134. package/dist/pages/profile/account.js.map +1 -0
  135. package/dist/pages/profile/layout.d.ts +8 -0
  136. package/dist/pages/profile/layout.js +133 -0
  137. package/dist/pages/profile/layout.js.map +1 -0
  138. package/dist/pages/profile/security.d.ts +5 -0
  139. package/dist/pages/profile/security.js +1539 -0
  140. package/dist/pages/profile/security.js.map +1 -0
  141. package/dist/{types-vcfvnAzQ.d.ts → types-g9QcNRxT.d.ts} +13 -7
  142. package/package.json +102 -3
@@ -0,0 +1,137 @@
1
+ "use client";
2
+
3
+ // src/components/iam/role-detail-layout.tsx
4
+ import {
5
+ EntityDetailHeader,
6
+ EntityEmptyState,
7
+ PageContainer,
8
+ useBreadcrumbs
9
+ } from "@mesob/ui/components";
10
+ import { IconShield } from "@tabler/icons-react";
11
+ import { useMemo as useMemo2 } from "react";
12
+
13
+ // src/provider.tsx
14
+ import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
15
+ import { deepmerge } from "deepmerge-ts";
16
+ import createFetchClient from "openapi-fetch";
17
+ import createClient from "openapi-react-query";
18
+ import { createContext, useContext, useMemo, useState } from "react";
19
+
20
+ // src/utils/cookie.ts
21
+ var isProduction = typeof process !== "undefined" && process.env.NODE_ENV === "production";
22
+
23
+ // src/provider.tsx
24
+ import { jsx } from "react/jsx-runtime";
25
+ var SessionContext = createContext(null);
26
+ var ApiContext = createContext(null);
27
+ var ConfigContext = createContext(null);
28
+ var queryClient = new QueryClient({
29
+ defaultOptions: {
30
+ queries: {
31
+ refetchOnWindowFocus: false
32
+ }
33
+ }
34
+ });
35
+ function useApi() {
36
+ const context = useContext(ApiContext);
37
+ if (!context) {
38
+ throw new Error("useApi must be used within MesobAuthProvider");
39
+ }
40
+ return context;
41
+ }
42
+ function useConfig() {
43
+ const context = useContext(ConfigContext);
44
+ if (!context) {
45
+ throw new Error("useConfig must be used within MesobAuthProvider");
46
+ }
47
+ return context;
48
+ }
49
+
50
+ // src/components/iam/role-detail-layout.tsx
51
+ import { jsx as jsx2, jsxs } from "react/jsx-runtime";
52
+ function str(value) {
53
+ if (value == null) {
54
+ return "";
55
+ }
56
+ if (typeof value === "string") {
57
+ return value;
58
+ }
59
+ if (typeof value === "object" && value !== null && "en" in value) {
60
+ const localized = value;
61
+ return localized.en ?? localized.am ?? "";
62
+ }
63
+ return String(value);
64
+ }
65
+ function RoleDetailLayout({
66
+ roleId,
67
+ basePath = "/iam/roles",
68
+ children
69
+ }) {
70
+ const { hooks } = useApi();
71
+ const { config } = useConfig();
72
+ const { data, isLoading, isFetching, isError } = hooks.useQuery(
73
+ "get",
74
+ "/roles/{id}",
75
+ { params: { path: { id: roleId } } },
76
+ { enabled: !!roleId }
77
+ );
78
+ const role = data?.role;
79
+ const title = role ? str(role.name) || role.code : roleId ?? "Role";
80
+ useBreadcrumbs({
81
+ items: [
82
+ { label: "Home", href: "/dashboard" },
83
+ { label: "IAM", href: "/iam" },
84
+ { label: "Roles", href: basePath },
85
+ { label: title }
86
+ ]
87
+ });
88
+ const tabs = useMemo2(
89
+ () => [
90
+ { value: "detail", name: "Detail", href: `${basePath}/${roleId}` },
91
+ {
92
+ value: "permissions",
93
+ name: "Permissions",
94
+ href: `${basePath}/${roleId}/permissions`
95
+ },
96
+ {
97
+ value: "users",
98
+ name: "Users",
99
+ href: `${basePath}/${roleId}/users`
100
+ }
101
+ ],
102
+ [basePath, roleId]
103
+ );
104
+ if (!roleId) {
105
+ return null;
106
+ }
107
+ const loading = isLoading || isFetching;
108
+ if (!(loading || role)) {
109
+ return /* @__PURE__ */ jsx2(PageContainer, { className: "flex flex-1 flex-col gap-4 p-4 pt-0", children: /* @__PURE__ */ jsx2(
110
+ EntityEmptyState,
111
+ {
112
+ icon: IconShield,
113
+ entityName: "role",
114
+ title: isError ? "Role unavailable" : "Role not found",
115
+ description: isError ? "Failed to load this role." : "This role no longer exists.",
116
+ actionLabel: "Back to roles",
117
+ onAction: () => config.navigation?.onNavigate?.(basePath) ?? window.history.back()
118
+ }
119
+ ) });
120
+ }
121
+ return /* @__PURE__ */ jsxs(PageContainer, { className: "flex flex-1 flex-col gap-4 p-4 pt-0", children: [
122
+ /* @__PURE__ */ jsx2(
123
+ EntityDetailHeader,
124
+ {
125
+ title,
126
+ icon: /* @__PURE__ */ jsx2(IconShield, { className: "h-5 w-5" }),
127
+ loading,
128
+ tabs
129
+ }
130
+ ),
131
+ children
132
+ ] });
133
+ }
134
+ export {
135
+ RoleDetailLayout
136
+ };
137
+ //# sourceMappingURL=role-detail-layout.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/components/iam/role-detail-layout.tsx","../../../src/provider.tsx","../../../src/utils/cookie.ts"],"sourcesContent":["'use client';\n\nimport {\n EntityDetailHeader,\n EntityEmptyState,\n PageContainer,\n type TabItem,\n useBreadcrumbs,\n} from '@mesob/ui/components';\nimport { IconShield } from '@tabler/icons-react';\nimport type { ReactNode } from 'react';\nimport { useMemo } from 'react';\nimport { useApi, useConfig } from '../../provider';\n\nfunction str(value: unknown): string {\n if (value == null) {\n return '';\n }\n if (typeof value === 'string') {\n return value;\n }\n if (typeof value === 'object' && value !== null && 'en' in value) {\n const localized = value as { en?: string; am?: string };\n return localized.en ?? localized.am ?? '';\n }\n return String(value);\n}\n\ntype RoleDetailLayoutProps = {\n roleId: string;\n basePath?: string;\n children: ReactNode;\n};\n\nexport function RoleDetailLayout({\n roleId,\n basePath = '/iam/roles',\n children,\n}: RoleDetailLayoutProps) {\n const { hooks } = useApi();\n const { config } = useConfig();\n const { data, isLoading, isFetching, isError } = hooks.useQuery(\n 'get',\n '/roles/{id}',\n { params: { path: { id: roleId } } },\n { enabled: !!roleId },\n );\n\n const role = data?.role;\n const title = role ? str(role.name) || role.code : (roleId ?? 'Role');\n\n useBreadcrumbs({\n items: [\n { label: 'Home', href: '/dashboard' },\n { label: 'IAM', href: '/iam' },\n { label: 'Roles', href: basePath },\n { label: title },\n ],\n });\n\n const tabs: TabItem[] = useMemo(\n () => [\n { value: 'detail', name: 'Detail', href: `${basePath}/${roleId}` },\n {\n value: 'permissions',\n name: 'Permissions',\n href: `${basePath}/${roleId}/permissions`,\n },\n {\n value: 'users',\n name: 'Users',\n href: `${basePath}/${roleId}/users`,\n },\n ],\n [basePath, roleId],\n );\n\n if (!roleId) {\n return null;\n }\n\n const loading = isLoading || isFetching;\n if (!(loading || role)) {\n return (\n <PageContainer className=\"flex flex-1 flex-col gap-4 p-4 pt-0\">\n <EntityEmptyState\n icon={IconShield}\n entityName=\"role\"\n title={isError ? 'Role unavailable' : 'Role not found'}\n description={\n isError\n ? 'Failed to load this role.'\n : 'This role no longer exists.'\n }\n actionLabel=\"Back to roles\"\n onAction={() =>\n config.navigation?.onNavigate?.(basePath) ?? window.history.back()\n }\n />\n </PageContainer>\n );\n }\n\n return (\n <PageContainer className=\"flex flex-1 flex-col gap-4 p-4 pt-0\">\n <EntityDetailHeader\n title={title}\n icon={<IconShield className=\"h-5 w-5\" />}\n loading={loading}\n tabs={tabs}\n />\n {children}\n </PageContainer>\n );\n}\n","'use client';\n\nimport { QueryClient, QueryClientProvider } from '@tanstack/react-query';\nimport { deepmerge } from 'deepmerge-ts';\nimport createFetchClient from 'openapi-fetch';\nimport createClient from 'openapi-react-query';\nimport type { ReactNode } from 'react';\nimport { createContext, useContext, useMemo, useState } from 'react';\nimport type { paths } from './data/openapi';\nimport { createTranslator } from './lib/translations';\nimport {\n type AuthClientConfig,\n type AuthResponse,\n defaultAuthClientConfig,\n type Session,\n type User,\n} from './types';\nimport { getSessionCookieName } from './utils/cookie';\nimport { createCustomFetch } from './utils/custom-fetch';\n\n// biome-ignore lint/suspicious/noExplicitAny: OpenAPI hooks type\ntype OpenApiHooks = any;\n\n// --- Utility: Check if running on server ---\nfunction isServer(): boolean {\n return typeof document === 'undefined';\n}\n\n/**\n * @deprecated Cookie is httpOnly and cannot be read client-side.\n * Use `useSession().isAuthenticated` instead.\n * This function always returns false on client.\n */\nexport function hasAuthCookie(_cookieName: string): boolean {\n // Cookie is httpOnly, can't check client-side\n // Always return false - use useSession() for auth status\n return false;\n}\n\n// --- Types ---\nexport type AuthStatus = 'loading' | 'authenticated' | 'unauthenticated';\n\ntype AuthState = {\n user: User | null;\n session: Session | null;\n status: AuthStatus;\n error: Error | null;\n};\n\ntype SessionContextValue = AuthState & {\n isLoading: boolean;\n isAuthenticated: boolean;\n refresh: () => Promise<void>;\n signOut: () => Promise<void>;\n};\n\ntype ApiContextValue = {\n hooks: OpenApiHooks;\n setAuth: (auth: AuthResponse) => void;\n clearAuth: () => void;\n refresh: () => Promise<void>;\n};\n\ntype ConfigContextValue = {\n config: AuthClientConfig;\n cookieName: string;\n t: (key: string, params?: Record<string, string | number>) => string;\n};\n\nconst SessionContext = createContext<SessionContextValue | null>(null);\nconst ApiContext = createContext<ApiContextValue | null>(null);\nconst ConfigContext = createContext<ConfigContextValue | null>(null);\n\nconst queryClient = new QueryClient({\n defaultOptions: {\n queries: {\n refetchOnWindowFocus: false,\n },\n },\n});\n\n// --- Hooks ---\n\n/**\n * Get session state including user, session, and auth status.\n * - `status`: 'loading' | 'authenticated' | 'unauthenticated'\n * - `isLoading`: true while fetching session\n * - `isAuthenticated`: true if user and session exist\n */\nexport function useSession(): SessionContextValue {\n const context = useContext(SessionContext);\n if (!context) {\n throw new Error('useSession must be used within MesobAuthProvider');\n }\n return context;\n}\n\nexport function useApi(): ApiContextValue {\n const context = useContext(ApiContext);\n if (!context) {\n throw new Error('useApi must be used within MesobAuthProvider');\n }\n return context;\n}\n\nexport function useConfig(): ConfigContextValue {\n const context = useContext(ConfigContext);\n if (!context) {\n throw new Error('useConfig must be used within MesobAuthProvider');\n }\n return context;\n}\n\n/**\n * @deprecated Cookie is httpOnly, can't be checked client-side.\n * Use `useSession().isAuthenticated` instead.\n */\nexport function useHasAuthCookie(): boolean {\n const { status } = useSession();\n return status === 'authenticated' || status === 'loading';\n}\n\n// --- Provider ---\n\ntype MesobAuthProviderProps = {\n config: AuthClientConfig;\n children: ReactNode;\n};\n\nexport function MesobAuthProvider({\n config,\n children,\n}: MesobAuthProviderProps) {\n const mergedConfig = useMemo(\n () =>\n deepmerge(\n { ...defaultAuthClientConfig } as Partial<AuthClientConfig>,\n config,\n ) as AuthClientConfig,\n [config],\n );\n\n const api = useMemo(\n () =>\n createFetchClient<paths>({\n baseUrl: mergedConfig.baseURL,\n fetch: createCustomFetch(mergedConfig),\n }),\n [mergedConfig],\n );\n\n const hooks = useMemo(() => createClient(api), [api]);\n const cookieName = useMemo(\n () => getSessionCookieName(mergedConfig),\n [mergedConfig],\n );\n\n return (\n <QueryClientProvider client={queryClient}>\n <AuthStateProvider\n config={mergedConfig}\n hooks={hooks}\n cookieName={cookieName}\n >\n {children}\n </AuthStateProvider>\n </QueryClientProvider>\n );\n}\n\ntype AuthStateProviderProps = {\n config: AuthClientConfig;\n hooks: OpenApiHooks;\n cookieName: string;\n children: ReactNode;\n};\n\nfunction AuthStateProvider({\n config,\n hooks,\n cookieName,\n children,\n}: AuthStateProviderProps) {\n // Manual override for sign-out / sign-in\n const [override, setOverride] = useState<AuthState | null>(null);\n\n // Always fetch session - cookie is httpOnly, can't check client-side\n // Server will read the cookie and return user/session if valid\n const {\n data: sessionData,\n isLoading,\n isFetched,\n error: sessionError,\n refetch,\n } = hooks.useQuery(\n 'get',\n '/session',\n {},\n {\n enabled: !(override || isServer()),\n refetchOnMount: false,\n refetchOnWindowFocus: false,\n refetchOnReconnect: false,\n retry: false,\n gcTime: 0,\n staleTime: 0,\n },\n );\n\n // Derive state directly - no useEffect\n const user = override?.user ?? sessionData?.user ?? null;\n const session = override?.session ?? sessionData?.session ?? null;\n const error = override?.error ?? (sessionError as Error | null);\n\n // Check error status code\n const errorStatus = (() => {\n if (!sessionError) {\n return null;\n }\n const err = sessionError as { status?: number };\n return err.status ?? null;\n })();\n\n // Check if error is a network/connection error\n const isNetworkError = (() => {\n if (!sessionError) {\n return false;\n }\n const error = sessionError as Error & { cause?: unknown; data?: unknown };\n const errorMessage =\n error.message || String(error) || JSON.stringify(error);\n // Network errors: TypeError, DOMException, or fetch failures\n if (\n error instanceof TypeError ||\n error instanceof DOMException ||\n error.name === 'TypeError' ||\n errorMessage.includes('Failed to fetch') ||\n errorMessage.includes('ERR_CONNECTION_REFUSED') ||\n errorMessage.includes('NetworkError') ||\n errorMessage.includes('Network request failed') ||\n errorMessage.includes('fetch failed')\n ) {\n return true;\n }\n // Check error cause\n if (error.cause) {\n const causeStr = String(error.cause);\n if (\n causeStr.includes('Failed to fetch') ||\n causeStr.includes('ERR_CONNECTION_REFUSED') ||\n causeStr.includes('NetworkError')\n ) {\n return true;\n }\n }\n return false;\n })();\n\n // Compute status\n // biome-ignore lint: Status determination requires multiple checks\n const status: AuthStatus = (() => {\n if (override) {\n return override.status;\n }\n if (isServer()) {\n return 'loading';\n }\n if (user && session) {\n return 'authenticated';\n }\n // Check for network errors or auth errors first - allow auth page to show\n if (isNetworkError || errorStatus === 401) {\n return 'unauthenticated';\n }\n // If we have an error but it's not a network error, still check loading state\n if (sessionError && !isNetworkError && errorStatus !== 401) {\n if (errorStatus && errorStatus >= 500) {\n return 'authenticated';\n }\n // Other errors mean unauthenticated\n if (isFetched) {\n return 'unauthenticated';\n }\n }\n if (isLoading || !isFetched) {\n return 'loading';\n }\n if (isFetched && !user && !session) {\n return 'unauthenticated';\n }\n return 'unauthenticated';\n })();\n\n const signOutMutation = hooks.useMutation('post', '/sign-out');\n const t = createTranslator(config.messages || {});\n\n const setAuth = (auth: AuthResponse) => {\n setOverride({\n user: auth.user,\n session: auth.session,\n status: 'authenticated',\n error: null,\n });\n };\n\n const clearAuth = () => {\n setOverride({\n user: null,\n session: null,\n status: 'unauthenticated',\n error: null,\n });\n };\n\n const refresh = async () => {\n setOverride(null);\n await refetch();\n };\n\n const signOut = async () => {\n try {\n await signOutMutation.mutateAsync({});\n } finally {\n clearAuth();\n }\n };\n\n return (\n <ConfigContext.Provider value={{ config, cookieName, t }}>\n <ApiContext.Provider value={{ hooks, setAuth, clearAuth, refresh }}>\n <SessionContext.Provider\n value={{\n user,\n session,\n status,\n error,\n isLoading: status === 'loading',\n isAuthenticated: status === 'authenticated',\n refresh,\n signOut,\n }}\n >\n {children}\n </SessionContext.Provider>\n </ApiContext.Provider>\n </ConfigContext.Provider>\n );\n}\n","import type { AuthClientConfig } from '../types';\n\nconst isProduction =\n typeof process !== 'undefined' && process.env.NODE_ENV === 'production';\n\nexport const getSessionCookieName = (config: AuthClientConfig): string => {\n const prefix = config.cookiePrefix || '';\n const baseName = 'session_token';\n if (prefix) {\n return `${prefix}_${baseName}`;\n }\n return isProduction ? '__Host-session_token' : baseName;\n};\n"],"mappings":";;;AAEA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EAEA;AAAA,OACK;AACP,SAAS,kBAAkB;AAE3B,SAAS,WAAAA,gBAAe;;;ACTxB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AAAA;AAAA,MAAC;AAAA;AAAA,QACC;AAAA,QACA,MAAM,gBAAAA,KAAC,cAAW,WAAU,WAAU;AAAA,QACtC;AAAA,QACA;AAAA;AAAA,IACF;AAAA,IACC;AAAA,KACH;AAEJ;","names":["useMemo","jsx","useMemo"]}
@@ -0,0 +1,9 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+
3
+ type RoleDetailPageProps = {
4
+ roleId: string;
5
+ basePath?: string;
6
+ };
7
+ declare function RoleDetailPage({ roleId, basePath, }: RoleDetailPageProps): react_jsx_runtime.JSX.Element | null;
8
+
9
+ export { RoleDetailPage };
@@ -0,0 +1,229 @@
1
+ "use client";
2
+
3
+ // src/components/iam/role-detail-page.tsx
4
+ import { zodResolver } from "@hookform/resolvers/zod";
5
+ import {
6
+ EntityFormActions,
7
+ Form,
8
+ FormControl,
9
+ FormField,
10
+ FormItem,
11
+ FormLabel,
12
+ FormMessage,
13
+ Input,
14
+ LocaleInputText,
15
+ LocaleInputTextarea,
16
+ Section,
17
+ Skeleton
18
+ } from "@mesob/ui/components";
19
+ import { useLocaleSchemas } from "@mesob/ui/providers";
20
+ import { useQueryClient } from "@tanstack/react-query";
21
+ import { useEffect, useMemo as useMemo2 } from "react";
22
+ import { useForm } from "react-hook-form";
23
+ import { toast } from "sonner";
24
+ import { z } from "zod";
25
+
26
+ // src/provider.tsx
27
+ import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
28
+ import { deepmerge } from "deepmerge-ts";
29
+ import createFetchClient from "openapi-fetch";
30
+ import createClient from "openapi-react-query";
31
+ import { createContext, useContext, useMemo, useState } from "react";
32
+
33
+ // src/utils/cookie.ts
34
+ var isProduction = typeof process !== "undefined" && process.env.NODE_ENV === "production";
35
+
36
+ // src/provider.tsx
37
+ import { jsx } from "react/jsx-runtime";
38
+ var SessionContext = createContext(null);
39
+ var ApiContext = createContext(null);
40
+ var ConfigContext = createContext(null);
41
+ var queryClient = new QueryClient({
42
+ defaultOptions: {
43
+ queries: {
44
+ refetchOnWindowFocus: false
45
+ }
46
+ }
47
+ });
48
+ function useApi() {
49
+ const context = useContext(ApiContext);
50
+ if (!context) {
51
+ throw new Error("useApi must be used within MesobAuthProvider");
52
+ }
53
+ return context;
54
+ }
55
+ function useConfig() {
56
+ const context = useContext(ConfigContext);
57
+ if (!context) {
58
+ throw new Error("useConfig must be used within MesobAuthProvider");
59
+ }
60
+ return context;
61
+ }
62
+
63
+ // src/components/iam/role-detail-page.tsx
64
+ import { jsx as jsx2, jsxs } from "react/jsx-runtime";
65
+ function RoleDetailPage({
66
+ roleId,
67
+ basePath = "/iam/roles"
68
+ }) {
69
+ const { hooks } = useApi();
70
+ const { config } = useConfig();
71
+ const qc = useQueryClient();
72
+ const { localeInputDefault, requiredSchema, optionalSchema } = useLocaleSchemas();
73
+ const schema = useMemo2(
74
+ () => z.object({
75
+ name: requiredSchema,
76
+ code: z.string().min(1, "Code is required"),
77
+ description: optionalSchema
78
+ }),
79
+ [requiredSchema, optionalSchema]
80
+ );
81
+ const defaults = useMemo2(
82
+ () => ({
83
+ name: { ...localeInputDefault },
84
+ code: "",
85
+ description: { ...localeInputDefault }
86
+ }),
87
+ [localeInputDefault]
88
+ );
89
+ const { data, isLoading } = hooks.useQuery(
90
+ "get",
91
+ "/roles/{id}",
92
+ { params: { path: { id: roleId } } },
93
+ { enabled: !!roleId }
94
+ );
95
+ const update = hooks.useMutation("put", "/roles/{id}", {
96
+ onSuccess: () => {
97
+ qc.invalidateQueries({ queryKey: ["get", "/roles"] });
98
+ qc.invalidateQueries({ queryKey: ["get", "/roles/{id}"] });
99
+ toast.success("Role updated");
100
+ },
101
+ onError: () => {
102
+ toast.error("Failed to update role");
103
+ }
104
+ });
105
+ const remove = hooks.useMutation("delete", "/roles/{id}", {
106
+ onSuccess: () => {
107
+ qc.invalidateQueries({ queryKey: ["get", "/roles"] });
108
+ toast.success("Role deleted");
109
+ config.navigation?.onNavigate?.(basePath);
110
+ },
111
+ onError: () => {
112
+ toast.error("Failed to delete role");
113
+ }
114
+ });
115
+ const form = useForm({
116
+ resolver: zodResolver(schema),
117
+ defaultValues: defaults
118
+ });
119
+ const { reset, formState, control, register } = form;
120
+ useEffect(() => {
121
+ if (!data?.role) {
122
+ return;
123
+ }
124
+ const r = data.role;
125
+ reset({
126
+ name: r.name ?? {},
127
+ code: r.code,
128
+ description: r.description ?? {}
129
+ });
130
+ }, [data?.role, reset]);
131
+ if (!roleId) {
132
+ return null;
133
+ }
134
+ const role = data?.role;
135
+ const editable = role?.isEditable !== false;
136
+ const deletable = role?.isDeletable !== false;
137
+ const onSubmit = form.handleSubmit(async (d) => {
138
+ await update.mutateAsync({
139
+ params: { path: { id: roleId } },
140
+ body: {
141
+ name: d.name,
142
+ code: d.code,
143
+ description: d.description ?? void 0
144
+ }
145
+ });
146
+ });
147
+ const footer = role ? /* @__PURE__ */ jsx2(
148
+ EntityFormActions,
149
+ {
150
+ mode: "edit",
151
+ onSubmit,
152
+ onDelete: deletable ? () => remove.mutate({
153
+ params: { path: { id: roleId } }
154
+ }) : void 0,
155
+ isSubmitting: update.isPending,
156
+ isDeleting: remove.isPending,
157
+ disabled: !editable,
158
+ itemName: "role"
159
+ }
160
+ ) : null;
161
+ return /* @__PURE__ */ jsx2(Section, { title: "Role details", footer, defaultOpen: true, children: isLoading || !role ? /* @__PURE__ */ jsx2(RoleDetailSkeleton, {}) : /* @__PURE__ */ jsx2(Form, { ...form, children: /* @__PURE__ */ jsxs("form", { onSubmit, className: "space-y-4", children: [
162
+ /* @__PURE__ */ jsx2(
163
+ LocaleInputText,
164
+ {
165
+ label: "Name",
166
+ field: "name",
167
+ required: true,
168
+ register,
169
+ errors: formState.errors,
170
+ placeholder: "e.g. Administrator",
171
+ disabled: !editable
172
+ }
173
+ ),
174
+ /* @__PURE__ */ jsx2(
175
+ FormField,
176
+ {
177
+ control,
178
+ name: "code",
179
+ render: ({ field }) => /* @__PURE__ */ jsxs(FormItem, { children: [
180
+ /* @__PURE__ */ jsxs(FormLabel, { children: [
181
+ "Code ",
182
+ /* @__PURE__ */ jsx2("span", { className: "text-destructive", children: "*" })
183
+ ] }),
184
+ /* @__PURE__ */ jsx2(FormControl, { children: /* @__PURE__ */ jsx2(
185
+ Input,
186
+ {
187
+ placeholder: "e.g. admin",
188
+ disabled: !editable,
189
+ ...field
190
+ }
191
+ ) }),
192
+ /* @__PURE__ */ jsx2(FormMessage, {})
193
+ ] })
194
+ }
195
+ ),
196
+ /* @__PURE__ */ jsx2(
197
+ LocaleInputTextarea,
198
+ {
199
+ label: "Description",
200
+ field: "description",
201
+ register,
202
+ errors: formState.errors,
203
+ placeholder: "Description",
204
+ rows: 3,
205
+ disabled: !editable
206
+ }
207
+ )
208
+ ] }) }) });
209
+ }
210
+ function RoleDetailSkeleton() {
211
+ return /* @__PURE__ */ jsxs("div", { className: "space-y-4", children: [
212
+ /* @__PURE__ */ jsxs("div", { className: "space-y-2", children: [
213
+ /* @__PURE__ */ jsx2(Skeleton, { className: "h-4 w-16" }),
214
+ /* @__PURE__ */ jsx2(Skeleton, { className: "h-10 w-full" })
215
+ ] }),
216
+ /* @__PURE__ */ jsxs("div", { className: "space-y-2", children: [
217
+ /* @__PURE__ */ jsx2(Skeleton, { className: "h-4 w-14" }),
218
+ /* @__PURE__ */ jsx2(Skeleton, { className: "h-10 w-full" })
219
+ ] }),
220
+ /* @__PURE__ */ jsxs("div", { className: "space-y-2", children: [
221
+ /* @__PURE__ */ jsx2(Skeleton, { className: "h-4 w-24" }),
222
+ /* @__PURE__ */ jsx2(Skeleton, { className: "h-20 w-full" })
223
+ ] })
224
+ ] });
225
+ }
226
+ export {
227
+ RoleDetailPage
228
+ };
229
+ //# sourceMappingURL=role-detail-page.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/components/iam/role-detail-page.tsx","../../../src/provider.tsx","../../../src/utils/cookie.ts"],"sourcesContent":["'use client';\n\nimport { zodResolver } from '@hookform/resolvers/zod';\nimport {\n EntityFormActions,\n Form,\n FormControl,\n FormField,\n FormItem,\n FormLabel,\n FormMessage,\n Input,\n LocaleInputText,\n LocaleInputTextarea,\n Section,\n Skeleton,\n} from '@mesob/ui/components';\nimport { useLocaleSchemas } from '@mesob/ui/providers';\nimport { useQueryClient } from '@tanstack/react-query';\nimport { useEffect, useMemo } from 'react';\nimport type { Resolver } from 'react-hook-form';\nimport { useForm } from 'react-hook-form';\nimport { toast } from 'sonner';\nimport { z } from 'zod';\nimport { useApi, useConfig } from '../../provider';\n\ntype RoleFormData = {\n name: Record<string, string>;\n code: string;\n description: Record<string, string>;\n};\n\ntype RoleDetailPageProps = {\n roleId: string;\n basePath?: string;\n};\n\nexport function RoleDetailPage({\n roleId,\n basePath = '/iam/roles',\n}: RoleDetailPageProps) {\n const { hooks } = useApi();\n const { config } = useConfig();\n const qc = useQueryClient();\n const { localeInputDefault, requiredSchema, optionalSchema } =\n useLocaleSchemas();\n const schema = useMemo(\n () =>\n z.object({\n name: requiredSchema,\n code: z.string().min(1, 'Code is required'),\n description: optionalSchema,\n }),\n [requiredSchema, optionalSchema],\n );\n const defaults: RoleFormData = useMemo(\n () => ({\n name: { ...localeInputDefault },\n code: '',\n description: { ...localeInputDefault },\n }),\n [localeInputDefault],\n );\n\n const { data, isLoading } = hooks.useQuery(\n 'get',\n '/roles/{id}',\n { params: { path: { id: roleId } } },\n { enabled: !!roleId },\n );\n\n const update = hooks.useMutation('put', '/roles/{id}', {\n onSuccess: () => {\n qc.invalidateQueries({ queryKey: ['get', '/roles'] });\n qc.invalidateQueries({ queryKey: ['get', '/roles/{id}'] });\n toast.success('Role updated');\n },\n onError: () => {\n toast.error('Failed to update role');\n },\n });\n const remove = hooks.useMutation('delete', '/roles/{id}', {\n onSuccess: () => {\n qc.invalidateQueries({ queryKey: ['get', '/roles'] });\n toast.success('Role deleted');\n config.navigation?.onNavigate?.(basePath);\n },\n onError: () => {\n toast.error('Failed to delete role');\n },\n });\n\n const form = useForm<RoleFormData>({\n resolver: zodResolver(schema) as Resolver<RoleFormData>,\n defaultValues: defaults,\n });\n\n const { reset, formState, control, register } = form;\n\n useEffect(() => {\n if (!data?.role) {\n return;\n }\n const r = data.role;\n reset({\n name: (r.name ?? {}) as RoleFormData['name'],\n code: r.code,\n description: (r.description ?? {}) as RoleFormData['description'],\n });\n }, [data?.role, reset]);\n\n if (!roleId) {\n return null;\n }\n\n const role = data?.role;\n const editable = role?.isEditable !== false;\n const deletable = role?.isDeletable !== false;\n const onSubmit = form.handleSubmit(async (d) => {\n await update.mutateAsync({\n params: { path: { id: roleId } },\n body: {\n name: d.name,\n code: d.code,\n description: d.description ?? undefined,\n },\n });\n });\n\n const footer = role ? (\n <EntityFormActions\n mode=\"edit\"\n onSubmit={onSubmit}\n onDelete={\n deletable\n ? () =>\n remove.mutate({\n params: { path: { id: roleId } },\n })\n : undefined\n }\n isSubmitting={update.isPending}\n isDeleting={remove.isPending}\n disabled={!editable}\n itemName=\"role\"\n />\n ) : null;\n\n return (\n <Section title=\"Role details\" footer={footer} defaultOpen>\n {isLoading || !role ? (\n <RoleDetailSkeleton />\n ) : (\n <Form {...form}>\n <form onSubmit={onSubmit} className=\"space-y-4\">\n <LocaleInputText\n label=\"Name\"\n field=\"name\"\n required\n register={register}\n errors={formState.errors}\n placeholder=\"e.g. Administrator\"\n disabled={!editable}\n />\n <FormField\n control={control}\n name=\"code\"\n render={({ field }) => (\n <FormItem>\n <FormLabel>\n Code <span className=\"text-destructive\">*</span>\n </FormLabel>\n <FormControl>\n <Input\n placeholder=\"e.g. admin\"\n disabled={!editable}\n {...field}\n />\n </FormControl>\n <FormMessage />\n </FormItem>\n )}\n />\n <LocaleInputTextarea\n label=\"Description\"\n field=\"description\"\n register={register}\n errors={formState.errors}\n placeholder=\"Description\"\n rows={3}\n disabled={!editable}\n />\n </form>\n </Form>\n )}\n </Section>\n );\n}\n\nfunction RoleDetailSkeleton() {\n return (\n <div className=\"space-y-4\">\n <div className=\"space-y-2\">\n <Skeleton className=\"h-4 w-16\" />\n <Skeleton className=\"h-10 w-full\" />\n </div>\n <div className=\"space-y-2\">\n <Skeleton className=\"h-4 w-14\" />\n <Skeleton className=\"h-10 w-full\" />\n </div>\n <div className=\"space-y-2\">\n <Skeleton className=\"h-4 w-24\" />\n <Skeleton className=\"h-20 w-full\" />\n </div>\n </div>\n );\n}\n","'use client';\n\nimport { QueryClient, QueryClientProvider } from '@tanstack/react-query';\nimport { deepmerge } from 'deepmerge-ts';\nimport createFetchClient from 'openapi-fetch';\nimport createClient from 'openapi-react-query';\nimport type { ReactNode } from 'react';\nimport { createContext, useContext, useMemo, useState } from 'react';\nimport type { paths } from './data/openapi';\nimport { createTranslator } from './lib/translations';\nimport {\n type AuthClientConfig,\n type AuthResponse,\n defaultAuthClientConfig,\n type Session,\n type User,\n} from './types';\nimport { getSessionCookieName } from './utils/cookie';\nimport { createCustomFetch } from './utils/custom-fetch';\n\n// biome-ignore lint/suspicious/noExplicitAny: OpenAPI hooks type\ntype OpenApiHooks = any;\n\n// --- Utility: Check if running on server ---\nfunction isServer(): boolean {\n return typeof document === 'undefined';\n}\n\n/**\n * @deprecated Cookie is httpOnly and cannot be read client-side.\n * Use `useSession().isAuthenticated` instead.\n * This function always returns false on client.\n */\nexport function hasAuthCookie(_cookieName: string): boolean {\n // Cookie is httpOnly, can't check client-side\n // Always return false - use useSession() for auth status\n return false;\n}\n\n// --- Types ---\nexport type AuthStatus = 'loading' | 'authenticated' | 'unauthenticated';\n\ntype AuthState = {\n user: User | null;\n session: Session | null;\n status: AuthStatus;\n error: Error | null;\n};\n\ntype SessionContextValue = AuthState & {\n isLoading: boolean;\n isAuthenticated: boolean;\n refresh: () => Promise<void>;\n signOut: () => Promise<void>;\n};\n\ntype ApiContextValue = {\n hooks: OpenApiHooks;\n setAuth: (auth: AuthResponse) => void;\n clearAuth: () => void;\n refresh: () => Promise<void>;\n};\n\ntype ConfigContextValue = {\n config: AuthClientConfig;\n cookieName: string;\n t: (key: string, params?: Record<string, string | number>) => string;\n};\n\nconst SessionContext = createContext<SessionContextValue | null>(null);\nconst ApiContext = createContext<ApiContextValue | null>(null);\nconst ConfigContext = createContext<ConfigContextValue | null>(null);\n\nconst queryClient = new QueryClient({\n defaultOptions: {\n queries: {\n refetchOnWindowFocus: false,\n },\n },\n});\n\n// --- Hooks ---\n\n/**\n * Get session state including user, session, and auth status.\n * - `status`: 'loading' | 'authenticated' | 'unauthenticated'\n * - `isLoading`: true while fetching session\n * - `isAuthenticated`: true if user and session exist\n */\nexport function useSession(): SessionContextValue {\n const context = useContext(SessionContext);\n if (!context) {\n throw new Error('useSession must be used within MesobAuthProvider');\n }\n return context;\n}\n\nexport function useApi(): ApiContextValue {\n const context = useContext(ApiContext);\n if (!context) {\n throw new Error('useApi must be used within MesobAuthProvider');\n }\n return context;\n}\n\nexport function useConfig(): ConfigContextValue {\n const context = useContext(ConfigContext);\n if (!context) {\n throw new Error('useConfig must be used within MesobAuthProvider');\n }\n return context;\n}\n\n/**\n * @deprecated Cookie is httpOnly, can't be checked client-side.\n * Use `useSession().isAuthenticated` instead.\n */\nexport function useHasAuthCookie(): boolean {\n const { status } = useSession();\n return status === 'authenticated' || status === 'loading';\n}\n\n// --- Provider ---\n\ntype MesobAuthProviderProps = {\n config: AuthClientConfig;\n children: ReactNode;\n};\n\nexport function MesobAuthProvider({\n config,\n children,\n}: MesobAuthProviderProps) {\n const mergedConfig = useMemo(\n () =>\n deepmerge(\n { ...defaultAuthClientConfig } as Partial<AuthClientConfig>,\n config,\n ) as AuthClientConfig,\n [config],\n );\n\n const api = useMemo(\n () =>\n createFetchClient<paths>({\n baseUrl: mergedConfig.baseURL,\n fetch: createCustomFetch(mergedConfig),\n }),\n [mergedConfig],\n );\n\n const hooks = useMemo(() => createClient(api), [api]);\n const cookieName = useMemo(\n () => getSessionCookieName(mergedConfig),\n [mergedConfig],\n );\n\n return (\n <QueryClientProvider client={queryClient}>\n <AuthStateProvider\n config={mergedConfig}\n hooks={hooks}\n cookieName={cookieName}\n >\n {children}\n </AuthStateProvider>\n </QueryClientProvider>\n );\n}\n\ntype AuthStateProviderProps = {\n config: AuthClientConfig;\n hooks: OpenApiHooks;\n cookieName: string;\n children: ReactNode;\n};\n\nfunction AuthStateProvider({\n config,\n hooks,\n cookieName,\n children,\n}: AuthStateProviderProps) {\n // Manual override for sign-out / sign-in\n const [override, setOverride] = useState<AuthState | null>(null);\n\n // Always fetch session - cookie is httpOnly, can't check client-side\n // Server will read the cookie and return user/session if valid\n const {\n data: sessionData,\n isLoading,\n isFetched,\n error: sessionError,\n refetch,\n } = hooks.useQuery(\n 'get',\n '/session',\n {},\n {\n enabled: !(override || isServer()),\n refetchOnMount: false,\n refetchOnWindowFocus: false,\n refetchOnReconnect: false,\n retry: false,\n gcTime: 0,\n staleTime: 0,\n },\n );\n\n // Derive state directly - no useEffect\n const user = override?.user ?? sessionData?.user ?? null;\n const session = override?.session ?? sessionData?.session ?? null;\n const error = override?.error ?? (sessionError as Error | null);\n\n // Check error status code\n const errorStatus = (() => {\n if (!sessionError) {\n return null;\n }\n const err = sessionError as { status?: number };\n return err.status ?? null;\n })();\n\n // Check if error is a network/connection error\n const isNetworkError = (() => {\n if (!sessionError) {\n return false;\n }\n const error = sessionError as Error & { cause?: unknown; data?: unknown };\n const errorMessage =\n error.message || String(error) || JSON.stringify(error);\n // Network errors: TypeError, DOMException, or fetch failures\n if (\n error instanceof TypeError ||\n error instanceof DOMException ||\n error.name === 'TypeError' ||\n errorMessage.includes('Failed to fetch') ||\n errorMessage.includes('ERR_CONNECTION_REFUSED') ||\n errorMessage.includes('NetworkError') ||\n errorMessage.includes('Network request failed') ||\n errorMessage.includes('fetch failed')\n ) {\n return true;\n }\n // Check error cause\n if (error.cause) {\n const causeStr = String(error.cause);\n if (\n causeStr.includes('Failed to fetch') ||\n causeStr.includes('ERR_CONNECTION_REFUSED') ||\n causeStr.includes('NetworkError')\n ) {\n return true;\n }\n }\n return false;\n })();\n\n // Compute status\n // biome-ignore lint: Status determination requires multiple checks\n const status: AuthStatus = (() => {\n if (override) {\n return override.status;\n }\n if (isServer()) {\n return 'loading';\n }\n if (user && session) {\n return 'authenticated';\n }\n // Check for network errors or auth errors first - allow auth page to show\n if (isNetworkError || errorStatus === 401) {\n return 'unauthenticated';\n }\n // If we have an error but it's not a network error, still check loading state\n if (sessionError && !isNetworkError && errorStatus !== 401) {\n if (errorStatus && errorStatus >= 500) {\n return 'authenticated';\n }\n // Other errors mean unauthenticated\n if (isFetched) {\n return 'unauthenticated';\n }\n }\n if (isLoading || !isFetched) {\n return 'loading';\n }\n if (isFetched && !user && !session) {\n return 'unauthenticated';\n }\n return 'unauthenticated';\n })();\n\n const signOutMutation = hooks.useMutation('post', '/sign-out');\n const t = createTranslator(config.messages || {});\n\n const setAuth = (auth: AuthResponse) => {\n setOverride({\n user: auth.user,\n session: auth.session,\n status: 'authenticated',\n error: null,\n });\n };\n\n const clearAuth = () => {\n setOverride({\n user: null,\n session: null,\n status: 'unauthenticated',\n error: null,\n });\n };\n\n const refresh = async () => {\n setOverride(null);\n await refetch();\n };\n\n const signOut = async () => {\n try {\n await signOutMutation.mutateAsync({});\n } finally {\n clearAuth();\n }\n };\n\n return (\n <ConfigContext.Provider value={{ config, cookieName, t }}>\n <ApiContext.Provider value={{ hooks, setAuth, clearAuth, refresh }}>\n <SessionContext.Provider\n value={{\n user,\n session,\n status,\n error,\n isLoading: status === 'loading',\n isAuthenticated: status === 'authenticated',\n refresh,\n signOut,\n }}\n >\n {children}\n </SessionContext.Provider>\n </ApiContext.Provider>\n </ConfigContext.Provider>\n );\n}\n","import type { AuthClientConfig } from '../types';\n\nconst isProduction =\n typeof process !== 'undefined' && process.env.NODE_ENV === 'production';\n\nexport const getSessionCookieName = (config: AuthClientConfig): string => {\n const prefix = config.cookiePrefix || '';\n const baseName = 'session_token';\n if (prefix) {\n return `${prefix}_${baseName}`;\n }\n return isProduction ? '__Host-session_token' : baseName;\n};\n"],"mappings":";;;AAEA,SAAS,mBAAmB;AAC5B;AAAA,EACE;AAAA,E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* as react_jsx_runtime from 'react/jsx-runtime';
2
+
3
+ type RolePermissionsPageProps = {
4
+ roleId: string;
5
+ };
6
+ declare function RolePermissionsPage({ roleId }: RolePermissionsPageProps): react_jsx_runtime.JSX.Element | null;
7
+
8
+ export { RolePermissionsPage };