From d5e99e77fdafd5490c505f0bd0d87ff3d0bcf619 Mon Sep 17 00:00:00 2001 From: CarolinaUniovi Date: Mon, 11 Mar 2024 18:46:48 +0100 Subject: [PATCH] only authenticated users are allowed to enter the application --- webapp/src/App.tsx | 1 + webapp/src/common/Nav.tsx | 6 ++++++ webapp/src/components/Login.tsx | 1 + webapp/src/pages/init/index.tsx | 2 ++ 4 files changed, 10 insertions(+) diff --git a/webapp/src/App.tsx b/webapp/src/App.tsx index 8387448..792dc60 100644 --- a/webapp/src/App.tsx +++ b/webapp/src/App.tsx @@ -5,6 +5,7 @@ import { AppRouter } from "./Router"; /** The old code is not in /pages/init/index.tsx and is shown as default */ function App() { + return ( diff --git a/webapp/src/common/Nav.tsx b/webapp/src/common/Nav.tsx index ca76b40..337ac1c 100644 --- a/webapp/src/common/Nav.tsx +++ b/webapp/src/common/Nav.tsx @@ -7,6 +7,12 @@ import { useNavigate } from "react-router-dom"; const NavBar: React.FC<{}> = () => { const { t } = useTranslation(); const navigate = useNavigate(); + const value :string= JSON.stringify( localStorage.getItem("isAuthenticated")).replace("\"","").replace("\"",""); + + if(value === "false"){ + navigate("/"); + } + return ( diff --git a/webapp/src/components/Login.tsx b/webapp/src/components/Login.tsx index 7fa80d5..d07bece 100644 --- a/webapp/src/components/Login.tsx +++ b/webapp/src/components/Login.tsx @@ -33,6 +33,7 @@ const Login = (props: ActionProps) => { localStorage.setItem("score", user.data.totalScore); localStorage.setItem("nWins", user.data.nWins); localStorage.setItem("uuid", user.data.uuid); + localStorage.setItem("isAuthenticated", JSON.stringify(true)); // Extract data from the response setOpenSnackbar(true); diff --git a/webapp/src/pages/init/index.tsx b/webapp/src/pages/init/index.tsx index 6a92c3e..923a186 100644 --- a/webapp/src/pages/init/index.tsx +++ b/webapp/src/pages/init/index.tsx @@ -29,6 +29,8 @@ export const InitPage: React.FC<{}> = () =>{ setShowInit(!showInit); } */ + localStorage.clear(); + localStorage.setItem("isAuthenticated", JSON.stringify(false)); return (