18 lines
441 B
TypeScript
18 lines
441 B
TypeScript
import { Navigate, useLocation } from "react-router-dom"
|
|
|
|
interface ProtectedRouteProps {
|
|
children: React.ReactNode
|
|
}
|
|
|
|
export function ProtectedRoute({ children }: ProtectedRouteProps) {
|
|
const location = useLocation()
|
|
const token = localStorage.getItem('access_token')
|
|
|
|
if (!token) {
|
|
// Redirect to login page with return URL
|
|
return <Navigate to="/login" state={{ from: location }} replace />
|
|
}
|
|
|
|
return <>{children}</>
|
|
}
|