Files
admin-frontend-domain/src/routes/protect.tsx
2024-11-05 00:02:43 +08:00

16 lines
410 B
TypeScript

import { Navigate } from "react-router-dom";
import { useAuth } from "@/hooks/useAuth";
export const ProtectedRoute = ({ children }: {
children: React.ReactNode;
}) => {
const { profile } = useAuth();
if (!profile && window.location.pathname !== "/dashboard/login") {
return <><Navigate to="/dashboard/login" />{children}</>;
}
return children;
};
export default ProtectedRoute;