auth
This commit is contained in:
@@ -6,10 +6,10 @@ import {
|
||||
OrderedListOutlined,
|
||||
UserOutlined,
|
||||
} from '@ant-design/icons'
|
||||
import { Avatar, Button, Layout, Menu, Result, Space, Spin, Tag, Typography } from 'antd'
|
||||
import { Avatar, Button, Layout, Menu, Result, Space, Tag, Typography } from 'antd'
|
||||
import { Outlet, useLocation } from 'react-router-dom'
|
||||
import { useAuth } from '@/auth/AuthContext'
|
||||
import { ROLE_MANAGE_AREA, ROLE_MANAGE_ATTRACTION } from '@/auth/roles'
|
||||
import { useAuth } from '@/auth/AuthContext'
|
||||
|
||||
const { Header, Sider, Content } = Layout
|
||||
|
||||
@@ -19,34 +19,9 @@ const ROLE_LABELS: Record<string, string> = {
|
||||
}
|
||||
|
||||
export function AdminLayout() {
|
||||
const { ready, authenticated, userName, roles, logout } = useAuth()
|
||||
const { email, roles, logout } = useAuth()
|
||||
const location = useLocation()
|
||||
|
||||
if (!ready) {
|
||||
return (
|
||||
<div className="fullscreen-spin">
|
||||
<Spin size="large" tip="Проверка авторизации…">
|
||||
<div style={{ width: 160, height: 60 }} />
|
||||
</Spin>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
if (!authenticated) {
|
||||
return (
|
||||
<Result
|
||||
status="warning"
|
||||
title="Не удалось авторизоваться"
|
||||
subTitle="Сервер Keycloak недоступен или сессия истекла. Попробуйте войти снова."
|
||||
extra={
|
||||
<Button type="primary" onClick={logout}>
|
||||
Войти заново
|
||||
</Button>
|
||||
}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
const hasManageArea = roles.includes(ROLE_MANAGE_AREA)
|
||||
const hasManageAttraction = roles.includes(ROLE_MANAGE_ATTRACTION)
|
||||
|
||||
@@ -55,7 +30,7 @@ export function AdminLayout() {
|
||||
<Result
|
||||
status="403"
|
||||
title="Нет административных прав"
|
||||
subTitle="Вашей учётной записи не назначена роль manage_area или manage_attraction в Keycloak."
|
||||
subTitle="Вашей учётной записи не назначена роль manage_area или manage_attraction. Обратитесь к администратору бэкенда."
|
||||
extra={
|
||||
<Button icon={<LogoutOutlined />} onClick={logout}>
|
||||
Выйти
|
||||
@@ -80,9 +55,7 @@ export function AdminLayout() {
|
||||
hasManageArea && { key: '/visits', icon: <BarChartOutlined />, label: 'Визиты' },
|
||||
].filter(Boolean) as { key: string; icon: React.ReactNode; label: string }[]
|
||||
|
||||
const selectedKey =
|
||||
'/' +
|
||||
(location.pathname.split('/')[1] ?? '')
|
||||
const selectedKey = '/' + (location.pathname.split('/')[1] ?? '')
|
||||
|
||||
return (
|
||||
<Layout style={{ minHeight: '100vh' }}>
|
||||
@@ -111,9 +84,7 @@ export function AdminLayout() {
|
||||
</Space>
|
||||
<Space size={8}>
|
||||
<Avatar size="small" icon={<UserOutlined />} />
|
||||
<Typography.Text style={{ color: 'rgba(255,255,255,0.85)' }}>
|
||||
{userName}
|
||||
</Typography.Text>
|
||||
<Typography.Text style={{ color: 'rgba(255,255,255,0.85)' }}>{email}</Typography.Text>
|
||||
<Button
|
||||
type="text"
|
||||
icon={<LogoutOutlined />}
|
||||
|
||||
Reference in New Issue
Block a user