Skip to content

Commit

Permalink
Añadido botón de cerrar sesión
Browse files Browse the repository at this point in the history
  • Loading branch information
uo276026 committed Mar 26, 2024
1 parent e199764 commit 61641a2
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
3 changes: 2 additions & 1 deletion webapp/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ function PrivateRoute({ element, ...props }) {

return (
<>
<Layout/>

<Router>
<Layout isLogged={isLogged} setIsLogged={setIsLogged} />
<Routes>
<Route path="/" element={<Home isLogged={isLogged}/>}></Route>
<Route path="/game"
Expand Down
24 changes: 21 additions & 3 deletions webapp/src/components/Pages/Layout.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
import { Outlet, Link } from "react-router-dom";
import React, { useState, useEffect } from 'react';
import {Container, Nav, Navbar, NavDropdown} from 'react-bootstrap';

const Layout = (isLogged) => {


const Layout = ({ isLogged, setIsLogged }) => {

function onLogout(){
localStorage.setItem('isLogged', JSON.stringify(false));
setIsLogged(false);
}


return (
<>
<Navbar collapseOnSelect expand="lg" className="bg-body-tertiary">
Expand All @@ -13,8 +23,16 @@ const Layout = (isLogged) => {
<Nav.Link href="stats">Estadísticas</Nav.Link>
</Nav>
<Nav>
<Nav.Link href="login">Inicia Sesión</Nav.Link>
<Nav.Link href="register">Regístrate</Nav.Link>
{isLogged ? (
<>
<Nav.Link onClick={onLogout}>Cerrar sesión</Nav.Link>
</>
) : (
<>
<Link to="login" className="nav-link">Inicia Sesión</Link>
<Link to="register" className="nav-link">Regístrate</Link>
</>
)}
</Nav>
</Navbar.Collapse>
</Container>
Expand Down

0 comments on commit 61641a2

Please sign in to comment.