import { useState } from "react"; import { useAuth } from "../contexts/AuthContext.tsx"; function AccountAvatar() { const { user, isLoading, logout } = useAuth(); const handleLogout = () => { logout(); window.location.href = "/"; }; const getInitials = (user: { name?: string; email?: string }): string => { if (user.name) { return user.name.substring(0, 2).toUpperCase(); } if (user.email) { return user.email.substring(0, 2).toUpperCase(); } return "?"; }; if (isLoading) { return
; } return ( <> {user ? (
{user.avatar ? ( {user.name ) : (
{getInitials(user)}
)}
Click to logout
) : ( )} ); } export default function Navigation() { const [isOpen, setIsOpen] = useState(false); const { user, logout } = useAuth(); const handleLogout = () => { logout(); window.location.href = "/"; }; return ( <>
{isOpen && ( <>
setIsOpen(false)} >
setIsOpen(false)} > Home setIsOpen(false)} > Blog setIsOpen(false)} > Guestbook {user && ( <>
{user.name || user.email}
)}
)} ); }