'use client'; import './globals.css'; import { QueryClient, QueryClientProvider } from '@tanstack/react-query'; import { useState, useEffect } from 'react'; import { usePathname, useRouter } from 'next/navigation'; import { AuthProvider, useAuth } from '@/lib/auth-context'; import { PermissionProvider } from '@/contexts/PermissionContext'; import Sidebar from '@/components/Sidebar'; import { Loader2 } from 'lucide-react'; function AuthenticatedLayout({ children }: { children: React.ReactNode }) { const pathname = usePathname(); const router = useRouter(); const { isLoading, isAuthenticated } = useAuth(); // Redirect to login if not authenticated (client-side) useEffect(() => { if (!isLoading && !isAuthenticated && pathname !== '/login') { router.push('/login'); } }, [isLoading, isAuthenticated, pathname, router]); // Don't show sidebar on login page if (pathname === '/login') { return <>{children}; } // Show loading state while checking auth or redirecting if (isLoading || !isAuthenticated) { return (

Loading...

); } // Show authenticated layout with sidebar return (
{children}
); } export default function RootLayout({ children, }: { children: React.ReactNode; }) { const [queryClient] = useState(() => new QueryClient({ defaultOptions: { queries: { retry: 1, refetchOnWindowFocus: false, }, }, })); return ( {children} ); }