Files
gatehouse-ui/src/components/layouts/ProtectedLayout.tsx
T

35 lines
1.0 KiB
TypeScript
Raw Normal View History

2026-01-16 17:31:25 +10:30
import { Navigate, Outlet } from 'react-router-dom';
import { useAuth } from '@/contexts/AuthContext';
import AuthenticatedLayout from './AuthenticatedLayout';
import MfaEnforcementLayout from './MfaEnforcementLayout';
import { useOrganizations } from '@/hooks/useOrganizations';
2026-01-16 17:31:25 +10:30
import { Loader2 } from 'lucide-react';
export default function ProtectedLayout() {
const { isAuthenticated, isLoading, requiresMfaEnrollment } = useAuth();
const { isLoading: isOrgsLoading } = useOrganizations();
2026-01-16 17:31:25 +10:30
if (isLoading || isOrgsLoading) {
2026-01-16 17:31:25 +10:30
return (
<div className="min-h-screen flex items-center justify-center bg-background">
<div className="flex flex-col items-center gap-4">
<Loader2 className="w-8 h-8 animate-spin text-primary" />
<p className="text-muted-foreground text-sm">Loading...</p>
</div>
</div>
);
}
if (!isAuthenticated) {
return <Navigate to="/login" replace />;
}
if (requiresMfaEnrollment) {
return <MfaEnforcementLayout />;
}
return (
<AuthenticatedLayout />
2026-01-16 17:31:25 +10:30
);
}