import { useState } from 'react'; import { useNavigate } from 'react-router-dom'; import { Button } from '@/components/ui/button'; import { UserAvatar } from '@/components/ui/user-avatar'; import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuLabel, DropdownMenuSeparator, DropdownMenuTrigger } from '@/components/ui/dropdown-menu'; import { User, Settings, LogOut } from 'lucide-react'; import { useAuth } from '@/hooks/useAuth'; import { useProfile } from '@/hooks/useProfile'; import { useToast } from '@/hooks/use-toast'; import { useAuthModal } from '@/hooks/useAuthModal'; import { getErrorMessage } from '@/lib/errorHandler'; export function AuthButtons() { const { user, loading: authLoading, signOut } = useAuth(); const { data: profile, isLoading: profileLoading } = useProfile(user?.id); const navigate = useNavigate(); const { toast } = useToast(); const { openAuthModal } = useAuthModal(); const [loggingOut, setLoggingOut] = useState(false); const handleSignOut = async () => { setLoggingOut(true); try { await signOut(); toast({ title: "Signed out", description: "You've been signed out successfully." }); navigate('/'); } catch (error: unknown) { const errorMsg = getErrorMessage(error); toast({ variant: "destructive", title: "Error signing out", description: errorMsg }); } finally { setLoggingOut(false); } }; // Show loading skeleton only during initial auth check if (authLoading) { return (
{profile?.display_name || profile?.username}
{user.email}