File size: 470 Bytes
5f9e2bb
17a8d4a
 
5f9e2bb
17a8d4a
 
 
 
 
 
 
 
 
5f9e2bb
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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}</>
}