import { Outlet, ScrollRestoration, useLocation, useNavigate, } from 'react-router-dom'; import { useEffect, useState } from 'react'; import { useAuthStore } from './features/auth/store/auth.store'; import { Sidebar } from '../components/Sidebar'; import { MenuOutlined } from '@ant-design/icons'; // Helper to determine route types const isPublicRoute = (pathname: string) => { return pathname.startsWith('/auth') || pathname === '/auth/callback'; }; export default function RootLayout() { const location = useLocation(); const navigate = useNavigate(); const { isAuthenticated } = useAuthStore(); const [mobileSidebarOpen, setMobileSidebarOpen] = useState(false); useEffect(() => { // If we're on a public route, no auth check needed if (isPublicRoute(location.pathname)) { return; } // AUTH CHECK if (!isAuthenticated) { // No session -> Redirect to login navigate('/auth/login', { replace: true }); return; } }, [location.pathname, navigate, isAuthenticated]); // RENDER LOGIC // 1. Public Pages (Full Layout Control) if (isPublicRoute(location.pathname)) { return ( <> ); } // 2. Protected Pages if (!isAuthenticated) { return null; } return (
setMobileSidebarOpen(false)} />
{/* Mobile Header */}

QR Campaign

); }