修复会话安全与实时消息

This commit is contained in:
yml2213
2026-07-14 15:06:01 +08:00
parent 064af29d3b
commit 8cff2a5824
29 changed files with 1961 additions and 546 deletions
+28
View File
@@ -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
+7 -2
View File
@@ -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"
/>