diff --git a/client/package-lock.json b/client/package-lock.json index 193f748..209bc1c 100644 --- a/client/package-lock.json +++ b/client/package-lock.json @@ -70,6 +70,7 @@ "integrity": "sha512-e7jT4DxYvIDLk1ZHmU/m/mB19rex9sv0c2ftBtjSBv+kVM/902eh0fINUzD7UwLLNR+jU585GxUJ8/EBfAM5fw==", "dev": true, "license": "MIT", + "peer": true, "dependencies": { "@babel/code-frame": "^7.27.1", "@babel/generator": "^7.28.5", @@ -1730,6 +1731,7 @@ "integrity": "sha512-6mDvHUFSjyT2B2yeNx2nUgMxh9LtOWvkhIU3uePn2I2oyNymUAX1NIsdgviM4CH+JSrp2D2hsMvJOkxY+0wNRA==", "devOptional": true, "license": "MIT", + "peer": true, "dependencies": { "csstype": "^3.0.2" } @@ -1777,6 +1779,7 @@ "integrity": "sha512-NZyJarBfL7nWwIq+FDL6Zp/yHEhePMNnnJ0y3qfieCrmNvYct8uvtiV41UvlSe6apAfk0fY1FbWx+NwfmpvtTg==", "dev": true, "license": "MIT", + "peer": true, "bin": { "acorn": "bin/acorn" }, @@ -1940,6 +1943,7 @@ } ], "license": "MIT", + "peer": true, "dependencies": { "baseline-browser-mapping": "^2.8.19", "caniuse-lite": "^1.0.30001751", @@ -2020,6 +2024,7 @@ "resolved": "https://registry.npmjs.org/chart.js/-/chart.js-4.5.1.tgz", "integrity": "sha512-GIjfiT9dbmHRiYi6Nl2yFCq7kkwdkp1W/lp2J99rX0yo9tgJGn3lKQATztIjb5tVtevcBtIdICNWqlq5+E8/Pw==", "license": "MIT", + "peer": true, "dependencies": { "@kurkle/color": "^0.3.0" }, @@ -2491,6 +2496,7 @@ "integrity": "sha512-t5aPOpmtJcZcz5UJyY2GbvpDlsK5E8JqRqoKtfiKE3cNh437KIqfJr3A3AKf5k64NPx6d0G3dno6XDY05PqPtw==", "dev": true, "license": "MIT", + "peer": true, "dependencies": { "@eslint-community/eslint-utils": "^4.8.0", "@eslint-community/regexpp": "^4.12.1", @@ -3647,6 +3653,7 @@ "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-4.0.3.tgz", "integrity": "sha512-5gTmgEY/sqK6gFXLIsQNH19lWb4ebPDLA4SdLP7dsWkIXHWlG66oPuVvXSGFPppYZz8ZDZq0dYYrbHfBCVUb1Q==", "license": "MIT", + "peer": true, "engines": { "node": ">=12" }, @@ -3673,6 +3680,7 @@ } ], "license": "MIT", + "peer": true, "dependencies": { "nanoid": "^3.3.11", "picocolors": "^1.1.1", @@ -3720,6 +3728,7 @@ "resolved": "https://registry.npmjs.org/react/-/react-19.2.0.tgz", "integrity": "sha512-tmbWg6W31tQLeB5cdIBOicJDJRR2KzXsV7uSK9iNfLWQ5bIZfxuPEHp7M8wiHyHnn0DD1i7w3Zmin0FtkrwoCQ==", "license": "MIT", + "peer": true, "engines": { "node": ">=0.10.0" } @@ -3739,6 +3748,7 @@ "resolved": "https://registry.npmjs.org/react-dom/-/react-dom-19.2.0.tgz", "integrity": "sha512-UlbRu4cAiGaIewkPyiRGJk0imDN2T3JjieT6spoL2UeSf5od4n5LB/mQ4ejmxhCFT1tYe8IvaFulzynWovsEFQ==", "license": "MIT", + "peer": true, "dependencies": { "scheduler": "^0.27.0" }, @@ -3767,6 +3777,7 @@ "resolved": "https://registry.npmjs.org/react-redux/-/react-redux-9.2.0.tgz", "integrity": "sha512-ROY9fvHhwOD9ySfrF0wmvu//bKCQ6AeZZq1nJNtbDC+kk5DuSuNX/n6YWYF/SYy7bSba4D4FSz8DJeKY/S/r+g==", "license": "MIT", + "peer": true, "dependencies": { "@types/use-sync-external-store": "^0.0.6", "use-sync-external-store": "^1.4.0" @@ -3889,7 +3900,8 @@ "version": "5.0.1", "resolved": "https://registry.npmjs.org/redux/-/redux-5.0.1.tgz", "integrity": "sha512-M9/ELqF6fy8FwmkpnF0S3YKOqMyoWJ4+CS5Efg2ct3oY9daQvd/Pc71FpGZsVsbl3Cpb+IIcjBDUnnyBdQbq4w==", - "license": "MIT" + "license": "MIT", + "peer": true }, "node_modules/redux-thunk": { "version": "3.1.0", @@ -4231,6 +4243,7 @@ "resolved": "https://registry.npmjs.org/vite/-/vite-7.1.12.tgz", "integrity": "sha512-ZWyE8YXEXqJrrSLvYgrRP7p62OziLW7xI5HYGWFzOvupfAlrLvURSzv/FyGyy0eidogEM3ujU+kUG1zuHgb6Ug==", "license": "MIT", + "peer": true, "dependencies": { "esbuild": "^0.25.0", "fdir": "^6.5.0", diff --git a/client/src/components/Navbar.jsx b/client/src/components/Navbar.jsx index 44f6bec..a4eb5cf 100644 --- a/client/src/components/Navbar.jsx +++ b/client/src/components/Navbar.jsx @@ -3,6 +3,7 @@ import React, { useState, useContext, useEffect, useRef } from "react"; import { useNavigate, useLocation } from "react-router-dom"; import axios from "axios"; import AppContent from "../context/AppContent"; +import { toast } from "react-toastify"; import { Menu, X, @@ -29,7 +30,7 @@ const NAV_LINKS = [ const Navbar = () => { const navigate = useNavigate(); const location = useLocation(); - const { backendUrl, userData, setUserData } = useContext(AppContent); + const { backendUrl, userData, setUserData, setIsLoggedin } = useContext(AppContent); const [menuOpen, setMenuOpen] = useState(false); const [mobileOpen, setMobileOpen] = useState(false); @@ -138,12 +139,18 @@ const Navbar = () => { {}, { withCredentials: true }, ); + } catch (err) { + console.warn( + "Backend logout cookie clearance skipped locally:", + err.message, + ); + } finally { setUserData(null); localStorage.removeItem("userData"); - window.location.href = "/login"; - } catch (err) { - console.error("Logout failed", err); - window.location.href = "/login"; + setIsLoggedin(false); + toast.success("Logged out successfully"); + + navigate("/"); } }; diff --git a/client/src/context/AppContext.jsx b/client/src/context/AppContext.jsx index 4e0678d..f9d924b 100644 --- a/client/src/context/AppContext.jsx +++ b/client/src/context/AppContext.jsx @@ -2,7 +2,7 @@ import axios from "axios"; import React, {useCallback, useEffect, useState } from "react"; import { toast } from "react-toastify"; import AppContent from "./AppContent.js"; - +import { useNavigate } from 'react-router-dom'; axios.defaults.withCredentials = true; @@ -14,6 +14,7 @@ const [isLoggedin, setIsLoggedin] = useState(false); const [userData, setUserData] = useState(null); const [loading, setLoading] = useState(true); const [isLoggingOut, setIsLoggingOut] = useState(false); +const navigate = useNavigate(); const getUserData = useCallback(async () => { try { @@ -85,6 +86,9 @@ const logoutUser = async () => { try { setIsLoggingOut(true); + toast.success("Logged out successfully"); + + navigate('/'); //FORCE REDIRECT TO LANDING PAGE (Prevents the 404 page) await axios.post( `${backendUrl}/api/auth/logout`, @@ -98,7 +102,6 @@ setIsLoggingOut(true); setUserData(null); localStorage.removeItem("userData"); - toast.success("Logged out successfully"); } catch { toast.error("Failed to logout"); } finally {