19 lines
471 B
JavaScript
19 lines
471 B
JavaScript
import React from 'react';
|
|
import { Navigate } from 'react-router-dom';
|
|
|
|
// Esta función verifica si el usuario está autenticado (por ejemplo, si hay un token en localStorage)
|
|
function isAuthenticated() {
|
|
const token = localStorage.getItem('access');
|
|
return !!token;
|
|
}
|
|
|
|
export default function RequireAuth({ children }) {
|
|
const authenticated = isAuthenticated();
|
|
|
|
if (!authenticated) {
|
|
return <Navigate to="/login" replace />;
|
|
}
|
|
|
|
return children;
|
|
}
|