15 lines
424 B
JavaScript
15 lines
424 B
JavaScript
import React from 'react';
|
|
import { Navigate, useLocation } from 'react-router-dom';
|
|
import { getToken } from './authMemory.js';
|
|
|
|
export default function ProtectedRoute({ children }) {
|
|
const location = useLocation();
|
|
const token = getToken();
|
|
|
|
if (!token) {
|
|
const next = encodeURIComponent(location.pathname + location.search);
|
|
return <Navigate to={`/signin?next=${next}`} replace />;
|
|
}
|
|
return children;
|
|
}
|