diff --git a/webapp/src/App.js b/webapp/src/App.js index b879f817..b4ae0b0f 100644 --- a/webapp/src/App.js +++ b/webapp/src/App.js @@ -1,4 +1,4 @@ -import React from 'react'; +import React, { useState } from 'react'; import Authenticate from './pages/Authenticate/Authenticate.js'; import Home from './pages/Home/Home.js'; import Clasico from './pages/Clasico/Clasico.js'; @@ -7,19 +7,24 @@ import WrongRoute from './pages/WrongRoute/WrongRoute.js'; import Stats from './pages/Stats/Stats.js'; import './App.css'; import {BrowserRouter, Routes, Route, Navigate} from "react-router-dom"; +import { ProtectedRoute } from './routers/ProtectedRoute.js'; function App() { + return ( {/** Rutas públicas */} } /> + } /> {/** Rutas privadas */} - } /> - } /> - } /> - } /> + }> + } /> + } /> + } /> + } /> + {/* Ruta por defecto */} } /> diff --git a/webapp/src/routers/ProtectedRoute.js b/webapp/src/routers/ProtectedRoute.js new file mode 100644 index 00000000..db8b6dc7 --- /dev/null +++ b/webapp/src/routers/ProtectedRoute.js @@ -0,0 +1,9 @@ +import { Navigate, Outlet } from 'react-router-dom' + +export const ProtectedRoute = ({children, redirectTo= "/login"}) => { + const token = localStorage.getItem('token'); + if(token == null || token == undefined){ + return + } + return children ? children : +} \ No newline at end of file