/** * Trouve-KA — bouton compte KA ID (header) * Author: Simon-Pierre Boucher * Contact: contact@spboucher.ai * * « Se connecter avec KA » : délègue l'identité au hub groupe-ka.com via * /api/auth/ka/login (SSO KA ID). Une fois connecté : nom + déconnexion. * La création de compte se fait TOUJOURS sur le hub (groupe-ka.com/connexion). */ "use client"; import { useEffect, useState } from "react"; import { usePathname } from "next/navigation"; type KaUser = { ka_id: string; email: string; name: string; picture: string; }; export function AuthButton() { const [user, setUser] = useState(null); const [ready, setReady] = useState(false); const pathname = usePathname(); useEffect(() => { let active = true; fetch("/api/auth/me", { cache: "no-store" }) .then((r) => (r.ok ? r.json() : { user: null })) .then((d: { user: KaUser | null }) => { if (active) setUser(d.user); }) .catch(() => {}) .finally(() => { if (active) setReady(true); }); return () => { active = false; }; }, []); const logout = async () => { try { await fetch("/api/auth/logout", { method: "POST" }); } catch { /* réseau indisponible : on recharge quand même */ } location.reload(); }; if (!ready) { return