"use client"; import type { ReactNode } from "react"; import { useAdminAuth } from "@/app/lib/AdminAuthContext"; import { useT } from "@/app/lib/i18n/MessagesProvider"; import { requiredModulesFor } from "@/app/lib/routeModules"; // UX-only gating (spec: "Access Is Gated By Role And Module, As UX Only" / // "Unseeded Portal Modules Fall Back Gracefully"). The server remains the // enforcement point; this only decides what the browser renders. export function NotAuthorized() { const t = useT() return (

{t("NotAuthorizedTitle")}

{t("NotAuthorizedBody")}

); } /** * Gates `children` behind the module(s) required for `pathname` (ROUTE_MODULES, * or any one of ROUTE_ANY_MODULES). A pathname with no entry in ROUTE_MODULES is ungated and * always renders its children. A gated pathname whose required module is * absent from the signed-in user's aclMenu renders NotAuthorized instead of * throwing — this covers the not-yet-seeded area-A module rows. */ export function RequireModule({ pathname, children }: { pathname: string; children: ReactNode }) { const { hasModule, loading } = useAdminAuth(); const required = requiredModulesFor(pathname); if (!required) return <>{children}; if (loading) return null; if (!required.some(hasModule)) return ; return <>{children}; }