mirror of
https://github.com/renee-png/acmcc.git
synced 2026-06-21 01:40:01 +00:00
8ac0edfbd9
Phase 1: gate the Accounting sidebar item and /dashboard/accounting route behind isAdmin via a RequireAdmin guard; Financial Reports stay visible. Phase 2: platform associations now read the Chart of Accounts from accounting.accounts (single source) instead of public.chart_of_accounts. Shared fetchChartOfAccounts() normalizes both sources; central COA hooks and ChartOfAccountsDropdown route through it (reads only, no migration). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
24 lines
760 B
TypeScript
24 lines
760 B
TypeScript
import { Navigate } from "react-router-dom";
|
|
import { useAuth } from "@/contexts/AuthContext";
|
|
|
|
/**
|
|
* Route guard for admin-only areas (e.g. the Accounting platform).
|
|
* Shows a spinner while auth resolves, then redirects non-admins to the
|
|
* dashboard. Admin status respects "view as" (uses effective `isAdmin`).
|
|
*/
|
|
export function RequireAdmin({ children }: { children: React.ReactNode }) {
|
|
const { loading, isAdmin } = useAuth();
|
|
|
|
if (loading) {
|
|
return (
|
|
<div className="flex min-h-[40vh] items-center justify-center">
|
|
<div className="h-8 w-8 animate-spin rounded-full border-4 border-primary border-t-transparent" />
|
|
</div>
|
|
);
|
|
}
|
|
|
|
if (!isAdmin) return <Navigate to="/dashboard" replace />;
|
|
|
|
return <>{children}</>;
|
|
}
|