import { ReactNode } from "react"; | |
import { Navigate } from "react-router-dom"; | |
import { useAuth } from "@/contexts/AuthContext"; | |
interface ProtectedRouteProps { | |
children: ReactNode; | |
} | |
export const ProtectedRoute = ({ children }: ProtectedRouteProps) => { | |
const { user, loading } = useAuth(); | |
if (loading) { | |
return <div className="flex h-screen items-center justify-center">Loading...</div>; | |
} | |
if (!user) { | |
return <Navigate to="/auth/login" />; | |
} | |
return <>{children}</>; | |
}; | |