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';
|
2026-02-27 21:08:16 +05:45
|
|
|
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();
|
2026-02-27 21:08:16 +05:45
|
|
|
const { isLoading: isOrgsLoading } = useOrganizations();
|
2026-01-16 17:31:25 +10:30
|
|
|
|
2026-02-27 21:08:16 +05:45
|
|
|
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 (
|
2026-02-27 21:08:16 +05:45
|
|
|
<AuthenticatedLayout />
|
2026-01-16 17:31:25 +10:30
|
|
|
);
|
|
|
|
|
}
|