MedRAG / frontend /src /components /ui /ProtectedRoute.jsx
hetsheta's picture
Initial commit
ea50fb7
Raw
History Blame Contribute Delete
507 Bytes
import { Navigate } from 'react-router-dom'
import { useAuthStore } from '../../store'
export function RequireAuth({ children }) {
const { isAuthenticated } = useAuthStore()
if (!isAuthenticated) return <Navigate to="/login" replace />
return children
}
export function RequireAdmin({ children }) {
const { isAuthenticated, user } = useAuthStore()
if (!isAuthenticated) return <Navigate to="/login" replace />
if (user?.role !== 'admin') return <Navigate to="/" replace />
return children
}