Skip to content

Commit

Permalink
only authenticated users are allowed to enter the application
Browse files Browse the repository at this point in the history
  • Loading branch information
carolbgmm committed Mar 11, 2024
1 parent c5e98fd commit d5e99e7
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions webapp/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<BrowserRouter>
<AppRouter />
Expand Down
6 changes: 6 additions & 0 deletions webapp/src/common/Nav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<AppBar className="nav_appBar">
<Toolbar>
Expand Down
1 change: 1 addition & 0 deletions webapp/src/components/Login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions webapp/src/pages/init/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ export const InitPage: React.FC<{}> = () =>{
setShowInit(!showInit);
} */

localStorage.clear();
localStorage.setItem("isAuthenticated", JSON.stringify(false));
return (
<Container component="main" maxWidth="xs">
<CssBaseline />
Expand Down

0 comments on commit d5e99e7

Please sign in to comment.