修复会话安全与实时消息
This commit is contained in:
@@ -7,4 +7,32 @@ const RequireAuth = () => {
|
||||
return <Outlet />
|
||||
}
|
||||
|
||||
export const RequirePlatformAdmin = () => {
|
||||
const { user } = useAuth()
|
||||
if (!user) return <Navigate to="/login" replace />
|
||||
if (user.role !== 'platform_admin') return <Navigate to="/agent/dashboard" replace />
|
||||
return <Outlet />
|
||||
}
|
||||
|
||||
export const RequireStaff = () => {
|
||||
const { user } = useAuth()
|
||||
if (!user) return <Navigate to="/login" replace />
|
||||
if (user.role === 'platform_admin') return <Navigate to="/admin/dashboard" replace />
|
||||
return <Outlet />
|
||||
}
|
||||
|
||||
export const RequireSupervisor = () => {
|
||||
const { user } = useAuth()
|
||||
if (!user) return <Navigate to="/login" replace />
|
||||
if (user.role !== 'admin' && user.role !== 'supervisor') return <Navigate to="/agent/dashboard" replace />
|
||||
return <Outlet />
|
||||
}
|
||||
|
||||
export const RequireTenantAdmin = () => {
|
||||
const { user } = useAuth()
|
||||
if (!user) return <Navigate to="/login" replace />
|
||||
if (user.role !== 'admin') return <Navigate to="/agent/dashboard" replace />
|
||||
return <Outlet />
|
||||
}
|
||||
|
||||
export default RequireAuth
|
||||
|
||||
@@ -21,8 +21,13 @@ const AgentSidebar = () => {
|
||||
const location = useLocation()
|
||||
const navigate = useNavigate()
|
||||
const { user, logout } = useAuth()
|
||||
const visibleMenuItems = menuItems.filter(item => {
|
||||
if (item.key === '/agent/statistics') return user?.role === 'admin' || user?.role === 'supervisor'
|
||||
if (item.key === '/agent/settings') return user?.role === 'admin'
|
||||
return true
|
||||
})
|
||||
|
||||
const selectedKey = menuItems.find(item => location.pathname.startsWith(item.key))?.key || '/agent/dashboard'
|
||||
const selectedKey = visibleMenuItems.find(item => location.pathname.startsWith(item.key))?.key || '/agent/dashboard'
|
||||
|
||||
const handleLogout = () => {
|
||||
logout()
|
||||
@@ -38,7 +43,7 @@ const AgentSidebar = () => {
|
||||
<Menu
|
||||
mode="inline"
|
||||
selectedKeys={[selectedKey]}
|
||||
items={menuItems}
|
||||
items={visibleMenuItems}
|
||||
onClick={({ key }) => navigate(key)}
|
||||
className="border-e-0 mt-2 flex-1"
|
||||
/>
|
||||
|
||||
Reference in New Issue
Block a user