import { useAuth } from '@/auth/useAuth' import { useTranslation } from 'react-i18next' import { IconButton } from '@/ui' import { SignInIcon, SignOutIcon, UserIcon } from '@phosphor-icons/react' /** * Бейдж в header'е: «Войти» если anonymous; имя + logout если залогинен. * *

Logout жмёт {@code signoutRedirect} — Keycloak инвалидирует SSO-сессию и * вернёт на post-logout-uri (корень). */ export function AuthBadge() { const { t } = useTranslation() const auth = useAuth() if (auth.isLoading) { return ( {t('loading')} ) } if (auth.error) { // Не валим UI — просто кнопка для повтора login. return ( ) } if (!auth.isAuthenticated) { // Compact sign-in button matching TopBar control style (h-8, surface bg). // Previously Button variant="primary" — слишком крупно, выбивалось из // toolbar style per user feedback ("кнопка Войти слишком большая"). return ( ) } const profile = auth.user?.profile const display = profile?.preferred_username || profile?.name || profile?.email || profile?.sub || 'user' return (

{display} } label={t('auth.logout')} onClick={() => auth.signoutRedirect().catch(() => { // Если Keycloak недоступен — просто очищаем локальный state. auth.removeUser() }) } />
) }