From b40129be21a504735bbc048bc6e6a76b71e64bf4 Mon Sep 17 00:00:00 2001 From: Amnyadav Date: Fri, 11 Oct 2024 12:08:00 +0530 Subject: [PATCH 1/2] chore: fixed unnecessary log in option after getting logged in using jwt token --- frontend/src/components/Pages/Login.jsx | 2 ++ frontend/src/components/Shared/Navbar.jsx | 11 ++++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/frontend/src/components/Pages/Login.jsx b/frontend/src/components/Pages/Login.jsx index c233e569..49e52855 100644 --- a/frontend/src/components/Pages/Login.jsx +++ b/frontend/src/components/Pages/Login.jsx @@ -34,6 +34,8 @@ const Login = () => { throw new Error(result.message || 'Login failed'); } // Handle successful login (e.g., store token, redirect) + const token=result.token; + localStorage.setItem("token",JSON.stringify(token)); message.success('Login successful'); navigate('/'); } catch (err) { diff --git a/frontend/src/components/Shared/Navbar.jsx b/frontend/src/components/Shared/Navbar.jsx index d9c7ef10..a3c70a7d 100644 --- a/frontend/src/components/Shared/Navbar.jsx +++ b/frontend/src/components/Shared/Navbar.jsx @@ -7,6 +7,7 @@ const Navbar = () => { const [isModalOpen, setIsModalOpen] = useState(false); const [isScrolled, setIsScrolled] = useState(false); const [isMenuOpen, setIsMenuOpen] = useState(false); + const token=localStorage.getItem("token"); const location = useLocation(); const navigate = useNavigate(); // Correctly initialize useNavigate @@ -36,8 +37,12 @@ const Navbar = () => { }; const handleLogout = () => { - setisloggedIn(false); // Set isLoggedIn to false on confirmation + // setisloggedIn(false); // Set isLoggedIn to false on confirmation + //managing log in , logout using jwt tokens + localStorage.removeItem("token"); setIsModalOpen(false); // Close the modal + setIsMenuOpen(false) // after getting logged out close the menu if it is open + navigate("/login");//navigate to login after get logged out }; const isHomePage = location.pathname === '/'; @@ -96,7 +101,7 @@ const Navbar = () => {
- {isloggedIn ? ( + {token ? (