| // src/components/ProtectedRoute.tsx | |
| import { Navigate } from "react-router-dom"; | |
| import { useAuth } from "@/context/AuthContext"; | |
| import { Loader2 } from "lucide-react"; | |
| interface ProtectedRouteProps { | |
| children: React.ReactNode; | |
| requiredRole?: "admin" | "author" | "user"; | |
| } | |
| export function ProtectedRoute({ children, requiredRole }: ProtectedRouteProps) { | |
| const { user, isLoading } = useAuth(); | |
| if (isLoading) { | |
| return ( | |
| <div className="flex h-screen items-center justify-center"> | |
| <Loader2 className="h-8 w-8 animate-spin text-primary" /> | |
| </div> | |
| ); | |
| } | |
| if (!user) { | |
| return <Navigate to="/login" replace />; | |
| } | |
| if (requiredRole && user.role !== requiredRole && user.role !== "admin") { | |
| return <Navigate to="/dashboard" replace />; | |
| } | |
| return <>{children}</>; | |
| } |
Xet Storage Details
- Size:
- 818 Bytes
- Xet hash:
- 8799a0e69ad009082e4a91d04989cbda472fe54991f00f2b4907eec87f6df8bb
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.