// Auteur : Simon-Pierre Boucher — contact@spboucher.ai /** * Bouton compte de l'en-tête (KA ID — SSO du Groupe KA). * · Déconnecté : pilule « KA ID » → /api/auth/ka/login?next= * · Connecté : avatar (ou initiale) + prénom → /compte * Composant client : interroge /api/auth/me au montage (session cookie httpOnly). */ "use client"; import { useEffect, useState } from "react"; import Link from "next/link"; import { usePathname } from "next/navigation"; import { useLang } from "./LangContext"; type MeUser = { ka_id: string; email: string; name: string; picture: string; provider: string; }; export default function AccountButton() { const { lang } = useLang(); const fr = lang === "fr"; const path = usePathname(); // undefined = chargement (on ne montre rien pour éviter le clignotement) const [user, setUser] = useState(undefined); useEffect(() => { let alive = true; fetch("/api/auth/me") .then((r) => r.json()) .then((d) => alive && setUser(d?.user ?? null)) .catch(() => alive && setUser(null)); return () => { alive = false; }; }, [path]); if (user === undefined) { return