import React, { useState } from 'react'; import styles from './navbar.module.css'; import { Link, NavLink, useNavigate } from 'react-router-dom'; import { authService } from '../utils/api'; export function Navbar({ isAuthenticated, user }) { const navigate = useNavigate(); const [isLoggingOut, setIsLoggingOut] = useState(false); const navClassName = ({ isActive }) => `${styles.navLink} ${isActive ? styles.active : ''}`.trim(); const handleLogout = async () => { if (isLoggingOut) return; try { setIsLoggingOut(true); // Clear auth data first localStorage.removeItem('token'); localStorage.removeItem('user'); sessionStorage.setItem('suppressSocialAutoLogin', '1'); // Call logout API authService.logout().catch(() => null); // Ignore errors // Dispatch auth change event to notify App component window.dispatchEvent(new Event('authchange')); // Small delay to ensure state updates before redirect setTimeout(() => { window.location.replace('/login'); }, 100); } finally { setIsLoggingOut(false); } }; return ( ); }