Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion client/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 12 additions & 5 deletions client/src/components/Navbar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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);
Expand Down Expand Up @@ -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("/");
Comment thread
coderabbitai[bot] marked this conversation as resolved.
}
};

Expand Down
7 changes: 5 additions & 2 deletions client/src/context/AppContext.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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 {
Expand Down Expand Up @@ -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`,
Expand All @@ -98,7 +102,6 @@ setIsLoggingOut(true);
setUserData(null);
localStorage.removeItem("userData");

toast.success("Logged out successfully");
} catch {
toast.error("Failed to logout");
} finally {
Expand Down
Loading