Bug fixed Logout Sidebar
This commit is contained in:
parent
34a4d7b05a
commit
50484287f2
@ -2,9 +2,9 @@
|
|||||||
import { useState, useEffect } from "react";
|
import { useState, useEffect } from "react";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
import { usePathname, useRouter } from "next/navigation";
|
import { usePathname, useRouter } from "next/navigation";
|
||||||
import { FileText, Moon, Sun } from "lucide-react";
|
import { FileText } from "lucide-react";
|
||||||
import { FaLock, FaChevronDown, FaChevronUp } from "react-icons/fa";
|
|
||||||
import { useTheme } from "../context/ThemeContext";
|
import { useTheme } from "../context/ThemeContext";
|
||||||
|
import { account } from "../lib/appwrite";
|
||||||
|
|
||||||
const Sidebar = ({ sidebarOpen, setSidebarOpen, isCollapsed }) => {
|
const Sidebar = ({ sidebarOpen, setSidebarOpen, isCollapsed }) => {
|
||||||
const pathname = usePathname();
|
const pathname = usePathname();
|
||||||
@ -25,10 +25,17 @@ const Sidebar = ({ sidebarOpen, setSidebarOpen, isCollapsed }) => {
|
|||||||
setSidebarOpen(false);
|
setSidebarOpen(false);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
const handleLogout = () => {
|
const handleLogout = async () => {
|
||||||
localStorage.removeItem("token"); // or account.deleteSession("current") if using Appwrite
|
try {
|
||||||
router.push("/signup");
|
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-----------------------
|
// ---------------logo handling in dark mode-----------------------
|
||||||
// Create a separate LogoImage component for better error handling
|
// Create a separate LogoImage component for better error handling
|
||||||
function LogoImage({ darkSrc, lightSrc, darkMode, className, alt }) {
|
function LogoImage({ darkSrc, lightSrc, darkMode, className, alt }) {
|
||||||
@ -71,7 +78,7 @@ const Sidebar = ({ sidebarOpen, setSidebarOpen, isCollapsed }) => {
|
|||||||
>
|
>
|
||||||
<div className="h-full flex flex-col border-r border-gray-200 p-4 overflow-y-auto scrollbar-hide">
|
<div className="h-full flex flex-col border-r border-gray-200 p-4 overflow-y-auto scrollbar-hide">
|
||||||
{/* Logo Section */}
|
{/* Logo Section */}
|
||||||
|
|
||||||
|
|
||||||
{/* MENU section - Only show when not collapsed */}
|
{/* MENU section - Only show when not collapsed */}
|
||||||
{!isCollapsed && (
|
{!isCollapsed && (
|
||||||
@ -87,12 +94,12 @@ const Sidebar = ({ sidebarOpen, setSidebarOpen, isCollapsed }) => {
|
|||||||
<Link
|
<Link
|
||||||
href="/dashboard"
|
href="/dashboard"
|
||||||
className={`flex items-center gap-2 p-3 rounded-md text-sm font-semibold transition-colors ${isActive("/dashboard")
|
className={`flex items-center gap-2 p-3 rounded-md text-sm font-semibold transition-colors ${isActive("/dashboard")
|
||||||
? darkMode
|
? darkMode
|
||||||
? "bg-blue-900 text-blue-200"
|
? "bg-blue-900 text-blue-200"
|
||||||
: "bg-blue-100 text-blue-800"
|
: "bg-blue-100 text-blue-800"
|
||||||
: darkMode
|
: darkMode
|
||||||
? "hover:bg-gray-700 text-gray-200"
|
? "hover:bg-gray-700 text-gray-200"
|
||||||
: "hover:bg-gray-200"
|
: "hover:bg-gray-200"
|
||||||
} ${isCollapsed ? 'justify-center' : ''}`}
|
} ${isCollapsed ? 'justify-center' : ''}`}
|
||||||
onClick={closeSidebarOnMobile}
|
onClick={closeSidebarOnMobile}
|
||||||
>
|
>
|
||||||
|
Loading…
Reference in New Issue
Block a user