// Auteur : Simon-Pierre Boucher — contact@spboucher.ai "use client"; import { useEffect, useState } from "react"; type Me = { name: string; avatarUrl: string | null; } | null; export default function UserButton({ variant = "full", }: { /** « icon » : pastille ronde seule (header mobile) ; « full » : avatar + prénom. */ variant?: "full" | "icon"; }) { const [me, setMe] = useState(null); const [loaded, setLoaded] = useState(false); useEffect(() => { fetch("/api/auth/me") .then((r) => r.json()) .then((d) => setMe(d.user)) .catch(() => setMe(null)) .finally(() => setLoaded(true)); }, []); if (variant === "icon") { const connected = loaded && me; return ( {connected && me!.avatarUrl ? ( // eslint-disable-next-line @next/next/no-img-element ) : connected ? ( {me!.name.slice(0, 1).toUpperCase()} ) : ( )} ); } if (loaded && me) { return ( {me.avatarUrl ? ( // eslint-disable-next-line @next/next/no-img-element ) : ( {me.name.slice(0, 1).toUpperCase()} )} {me.name.split(" ")[0]} ); } return ( KA ID ); }