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 ( } onClick={() => auth.signinRedirect()} > {t('auth.login')} ) } if (!auth.isAuthenticated) { return ( } onClick={() => auth.signinRedirect()} > {t('auth.login')} ) } const profile = auth.user?.profile const display = profile?.preferred_username || profile?.name || profile?.email || profile?.sub || 'user' return (