From 8598aea44514e889c556778ee56c650c7dd1da6d Mon Sep 17 00:00:00 2001 From: kkfluous Date: Thu, 16 Apr 2026 21:47:57 +0800 Subject: [PATCH] feat(scheduling): restrict scheduling module to allowed users only Only userId 1105261382487539712 and 1116631120763437056 can see the scheduling tab. Other users see only assets + mileage modules. - Add userId to frontend AuthState.user type - App.tsx conditionally includes scheduling module based on user ID - Backend already returns userId in auth exchange response Co-Authored-By: Claude Opus 4.6 (1M context) --- src/App.tsx | 24 ++++++++++++++++++++---- src/auth/useAuth.ts | 2 +- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index 044a887..15b100d 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,3 +1,4 @@ +import { useMemo } from 'react'; import { Truck, Route, Activity } from 'lucide-react'; import { Shell, type ModuleConfig } from './components/Shell'; import AssetsModule from './modules/assets/AssetsModule'; @@ -7,14 +8,29 @@ import AuthProvider from './auth/AuthProvider'; import { useAuth } from './auth/useAuth'; import UnauthorizedPage from './auth/UnauthorizedPage'; -const MODULES: ModuleConfig[] = [ +const SCHEDULING_ALLOWED_USERS = new Set([ + '1105261382487539712', + '1116631120763437056', +]); + +const BASE_MODULES: ModuleConfig[] = [ { id: 'assets', label: '资产管理', icon: Truck, component: AssetsModule }, { id: 'mileage', label: '里程管理', icon: Route, component: MileageModule }, - { id: 'scheduling', label: '智能调度', icon: Activity, component: SchedulingModule }, ]; +const SCHEDULING_MODULE: ModuleConfig = { + id: 'scheduling', label: '智能调度', icon: Activity, component: SchedulingModule, +}; + function AuthGate() { - const { isLoading, isAuthenticated, error } = useAuth(); + const { isLoading, isAuthenticated, error, user } = useAuth(); + + const modules = useMemo(() => { + if (user?.userId && SCHEDULING_ALLOWED_USERS.has(user.userId)) { + return [...BASE_MODULES, SCHEDULING_MODULE]; + } + return BASE_MODULES; + }, [user?.userId]); if (isLoading) { return ( @@ -31,7 +47,7 @@ function AuthGate() { return ; } - return ; + return ; } export default function App() { diff --git a/src/auth/useAuth.ts b/src/auth/useAuth.ts index c6385ec..0f8f7aa 100644 --- a/src/auth/useAuth.ts +++ b/src/auth/useAuth.ts @@ -3,7 +3,7 @@ import { createContext, useContext } from 'react'; export interface AuthState { isLoading: boolean; isAuthenticated: boolean; - user: { userName: string; permissionLevel: string; depName: string } | null; + user: { userId: string; userName: string; permissionLevel: string; depName: string } | null; error: string | null; }