({ children, allowedRoles }: { children: React.ReactNode; allowedRoles?: string[] })
| 31 | |
| 32 | // 受保护的路由组件 |
| 33 | const ProtectedRoute = ({ children, allowedRoles }: { children: React.ReactNode; allowedRoles?: string[] }) => { |
| 34 | const { isAuthenticated, user } = useAuthStore() |
| 35 | |
| 36 | if (!isAuthenticated) { |
| 37 | return <Navigate to="/login" replace /> |
| 38 | } |
| 39 | |
| 40 | if (allowedRoles && user && !allowedRoles.includes(user.role)) { |
| 41 | return <Navigate to="/" replace /> |
| 42 | } |
| 43 | |
| 44 | return <>{children}</> |
| 45 | } |
| 46 | |
| 47 | function App() { |
| 48 | const { isAuthenticated, user } = useAuthStore() |
nothing calls this directly
no outgoing calls
no test coverage detected