From 50484287f2de151a6d223cf4539538420c515f62 Mon Sep 17 00:00:00 2001 From: Mahima Sonwane Date: Tue, 13 May 2025 12:27:24 +0530 Subject: [PATCH] Bug fixed Logout Sidebar --- src/app/components/Sidebar.jsx | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/src/app/components/Sidebar.jsx b/src/app/components/Sidebar.jsx index 74f9662..0d42da5 100644 --- a/src/app/components/Sidebar.jsx +++ b/src/app/components/Sidebar.jsx @@ -2,9 +2,9 @@ import { useState, useEffect } from "react"; import Link from "next/link"; import { usePathname, useRouter } from "next/navigation"; -import { FileText, Moon, Sun } from "lucide-react"; -import { FaLock, FaChevronDown, FaChevronUp } from "react-icons/fa"; +import { FileText } from "lucide-react"; import { useTheme } from "../context/ThemeContext"; +import { account } from "../lib/appwrite"; const Sidebar = ({ sidebarOpen, setSidebarOpen, isCollapsed }) => { const pathname = usePathname(); @@ -25,10 +25,17 @@ const Sidebar = ({ sidebarOpen, setSidebarOpen, isCollapsed }) => { setSidebarOpen(false); } }; - const handleLogout = () => { - localStorage.removeItem("token"); // or account.deleteSession("current") if using Appwrite - router.push("/signup"); + const handleLogout = async () => { + try { + await account.deleteSession("current"); + localStorage.removeItem("token"); + // Force a full page reload to reset all state + window.location.href = "/"; + } catch (error) { + console.error("Logout failed:", error); + } }; + // ---------------logo handling in dark mode----------------------- // Create a separate LogoImage component for better error handling function LogoImage({ darkSrc, lightSrc, darkMode, className, alt }) { @@ -71,7 +78,7 @@ const Sidebar = ({ sidebarOpen, setSidebarOpen, isCollapsed }) => { >
{/* Logo Section */} - + {/* MENU section - Only show when not collapsed */} {!isCollapsed && ( @@ -87,12 +94,12 @@ const Sidebar = ({ sidebarOpen, setSidebarOpen, isCollapsed }) => {