import { ReactNode } from 'react'
import { Navigate, useLocation } from 'react-router-dom'
import { useAuthStore } from '../stores/auth'
// Route guard: redirects to /login when no token is present.
export function RequireAuth({ children }: { children: ReactNode }) {
const token = useAuthStore((s) => s.token)
const location = useLocation()
if (!token) {
return
}
return <>{children}>
}
// Route guard: only allows users with role === "admin".
export function RequireAdmin({ children }: { children: ReactNode }) {
const user = useAuthStore((s) => s.user)
if (user?.role !== 'admin') {
return
}
return <>{children}>
}