"use client"; import { useState } from "react"; import { LogOut } from "lucide-react"; import { getApiUrl } from "@/utils/api"; import { MixpanelEvent, trackEvent } from "@/utils/mixpanel"; type LogoutButtonProps = { label?: string; className?: string; iconOnly?: boolean; }; export default function LogoutButton({ label = "Logout", className = "", iconOnly = false, }: LogoutButtonProps) { const [isSubmitting, setIsSubmitting] = useState(false); const handleLogout = async () => { if (isSubmitting) { return; } setIsSubmitting(true); trackEvent(MixpanelEvent.Auth_Signed_Out, { source: "logout_button", }); try { await fetch(getApiUrl("/api/v1/auth/logout"), { method: "POST", credentials: "include", }); } catch { // Always route back to auth gate even if backend logout fails. } finally { window.location.replace("/"); setIsSubmitting(false); } }; return ( ); }