import { NavigateToSignIn, useSession } from "@wacht/react-router";
export function GuardedAdminDashboard({ children }: { children: React.ReactNode }) {
const { loading, session } = useSession();
// 1. Wait for the SDK to parse the HTTP cookies natively
if (loading) {
return <div className="animate-pulse h-screen w-full bg-zinc-100 flex items-center justify-center">Loading...</div>;
}
// 2. If the user isn't authenticated, trigger the redirect instantly
// simply by returning this component instead of the page markup.
if (!session) {
return <NavigateToSignIn />;
}
// 3. User is authenticated, safe to render the dashboard
return <div className="dashboard-layout">{children}</div>;
}