fix: add auth guard redirect and wire logout into NavAccountCard

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-03-16 16:11:59 +05:30
parent 3b68605561
commit 8b796bf916
4 changed files with 46 additions and 21 deletions

View File

@@ -8,13 +8,12 @@ import {
faGrid2,
faPlug,
} from "@fortawesome/pro-regular-svg-icons";
import { useNavigate } from "react-router";
import { MobileNavigationHeader } from "@/components/application/app-navigation/base-components/mobile-header";
import { NavAccountCard } from "@/components/application/app-navigation/base-components/nav-account-card";
import { NavItemBase } from "@/components/application/app-navigation/base-components/nav-item";
import type { NavItemType } from "@/components/application/app-navigation/config";
// TODO: Wire to useAuth() once auth-provider.tsx is implemented
const isAdmin = false;
import { useAuth } from "@/providers/auth-provider";
const MAIN_SIDEBAR_WIDTH = 292;
@@ -58,10 +57,18 @@ interface SidebarProps {
}
export const Sidebar = ({ activeUrl = "/" }: SidebarProps) => {
const { logout, isAdmin: authIsAdmin, user } = useAuth();
const navigate = useNavigate();
const handleSignOut = () => {
logout();
navigate('/login');
};
const navSections = [
{ label: "Main", items: mainItems },
{ label: "Insights", items: insightsItems },
...(isAdmin ? [{ label: "Admin", items: adminItems }] : []),
...(authIsAdmin ? [{ label: "Admin", items: adminItems }] : []),
];
const content = (
@@ -103,7 +110,7 @@ export const Sidebar = ({ activeUrl = "/" }: SidebarProps) => {
{/* Account card */}
<div className="mt-auto flex flex-col gap-5 px-2 py-4 lg:gap-6 lg:px-4 lg:py-4">
<NavAccountCard />
<NavAccountCard onSignOut={handleSignOut} />
</div>
</aside>
);