tahamajs/IE / Projects /front /src /components /admin /AdminGuard.tsx
tahamajs's picture
download
raw
658 Bytes
// src/components/admin/AdminGuard.tsx
import { Navigate } from "react-router-dom";
import { useAuth } from "@/context/AuthContext";
import { Loader2 } from "lucide-react";
interface AdminGuardProps {
children: React.ReactNode;
}
export default function AdminGuard({ children }: AdminGuardProps) {
const { user, isLoading } = useAuth();
if (isLoading) {
return (
<div className="flex items-center justify-center min-h-[60vh]">
<Loader2 className="w-8 h-8 animate-spin text-primary" />
</div>
);
}
if (!user || user.role !== "admin") {
return <Navigate to="/dashboard" replace />;
}
return <>{children}</>;
}

Xet Storage Details

Size:
658 Bytes
·
Xet hash:
52e8c7449be8660e6990491a85b16a96c58345f5f2c8e66e2127062a17c8a9ed

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.