Labour-Connect / admin /src /auth /ProtectedRoute.tsx
Abhisingh-18's picture
Mirror of github.com/Abhisingh18/Labour-Connect
b24b684 verified
Raw
History Blame Contribute Delete
548 Bytes
import { Box, CircularProgress } from "@mui/material";
import { Navigate, Outlet } from "react-router-dom";
import { useAuth } from "./AuthContext";
export default function ProtectedRoute() {
const { user, loading } = useAuth();
if (loading) {
return (
<Box
sx={{
height: "100vh",
display: "grid",
placeItems: "center",
}}
>
<CircularProgress />
</Box>
);
}
if (!user) return <Navigate to="/login" replace />;
return <Outlet />;
}