diff --git a/client/src/components/navbar.jsx b/client/src/components/navbar.jsx index aa7b083..48123e9 100644 --- a/client/src/components/navbar.jsx +++ b/client/src/components/navbar.jsx @@ -2,18 +2,44 @@ import React, { useState } from 'react'; import { MessageCircle, Menu, X } from 'lucide-react'; -// importing useNavigate -import { Link, useNavigate } from 'react-router-dom'; +// importing useNavigate and useLocation +import { Link, useLocation, useNavigate } from 'react-router-dom'; export default function Navbar() { const [menuOpen, setMenuOpen] = useState(false); const toggleMenu = () => setMenuOpen(!menuOpen); const navigate = useNavigate(); + const location = useLocation(); + const currentpath = location.pathname; + // a condition to check whethere the current page is login/signup page + const hideLogout = currentpath==="/authpage"; + const handleSignup = ()=>{ navigate('/authpage'); } + // a function to handle Logout feature + const handleLogoutuser =async ()=>{ + try { + const response = await fetch(`http://localhost:5000/api/auth/logout`, { + method: "GET", + credentials: "include", + }); + + const data = await response.json(); + if (response.ok) { + // a message to verify the logout which is send by backend + console.log(data.message); + navigate("/authpage"); + } else { + console.error("Logout failed:", data.message); + } + } catch (err) { + console.error("Logout error:", err); + } + }; + return (