2026-03-11 07:27:52 +00:00
|
|
|
import { Navigate, useLocation } from 'react-router-dom'
|
2025-12-20 11:18:59 +00:00
|
|
|
|
|
|
|
|
function ProtectedRoute({ children }) {
|
2026-03-11 07:27:52 +00:00
|
|
|
const location = useLocation()
|
2025-12-20 11:18:59 +00:00
|
|
|
const token = localStorage.getItem('access_token')
|
|
|
|
|
|
|
|
|
|
if (!token) {
|
2026-03-11 07:27:52 +00:00
|
|
|
const returnTo = encodeURIComponent(`${location.pathname}${location.search}${location.hash}`)
|
|
|
|
|
return <Navigate to={`/login?redirect=${returnTo}`} replace />
|
2025-12-20 11:18:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return children
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default ProtectedRoute
|