Spaces:
Sleeping
Sleeping
| import { type ReactNode } from 'react' | |
| import { Navigate } from 'react-router-dom' | |
| import { useAuthStore } from '../../store/authStore' | |
| interface Props { | |
| children: ReactNode | |
| role: 'student' | 'instructor' | |
| } | |
| export default function ProtectedRoute({ children, role }: Props) { | |
| const user = useAuthStore((s) => s.user) | |
| if (!user) return <Navigate to="/login" replace /> | |
| if (user.role !== role) return <Navigate to="/login" replace /> | |
| return <>{children}</> | |
| } | |