import { Navigate } from 'react-router-dom'
import { useAuth } from '../../context/AuthContext'
import { PageLoader } from './Spinner'
export function ProtectedRoute({ children, role }) {
const { user, loading } = useAuth()
if (loading) return
if (!user) return
if (role === 'admin' && user.role !== 'admin') return
if (role === 'aspirant' && !['admin', 'aspirant'].includes(user.role)) return
return children
}
export function GuestRoute({ children }) {
const { user, loading } = useAuth()
if (loading) return
if (user) {
if (user.role === 'admin') return
if (user.role === 'aspirant') return
return
}
return children
}