import { Navigate, useLocation } from 'react-router-dom'
import { useAppSelector } from '@/store'

export default function RequireAuth({ children }: { children: React.ReactNode }) {
  const token = useAppSelector(s => s.auth.token)
  const loc = useLocation()
  if (!token) return <Navigate to="/login" replace state={{ from: loc.pathname }} />
  return <>{children}</>
}
