From ba57c40471e78e952c2d8da32312e033f5a4b672 Mon Sep 17 00:00:00 2001 From: Steve White Date: Sat, 12 Oct 2024 11:27:42 -0500 Subject: [PATCH] Added logout button --- src/App.js | 14 ++++++++++---- src/components/Navbar.js | 21 ++++++++++++++++++++- 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/src/App.js b/src/App.js index f6b7715..45ff38c 100644 --- a/src/App.js +++ b/src/App.js @@ -6,10 +6,14 @@ import Login from './components/Login'; import Boxes from './components/Boxes'; import Items from './components/Items'; import Navbar from './components/Navbar'; // Correct import here +import { createContext } from 'react'; import './styles.css' +export const AppContext = createContext(); + function App() { const [token, setToken] = useState(localStorage.getItem('token')); + useEffect(() => { if (token) { localStorage.setItem('token', token); @@ -17,9 +21,12 @@ function App() { }, [token]); return ( - - - + + + + + + ); } @@ -28,7 +35,6 @@ function AppRoutes({ token, setToken }) { return ( <> - } /> { + localStorage.removeItem('token'); + setToken(null); + navigate('/login'); + }; + return ( @@ -13,6 +31,7 @@ export default function Navbar() { + );