import { useAuth } from 'react-oidc-context' import { useTranslation } from 'react-i18next' import { Button, 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) { 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() }) } />
) }