MCPcopy Create free account
hub / github.com/LQF-dev/smart-hr / ProtectedRoute

Function ProtectedRoute

front/src/App.tsx:33–45  ·  view source on GitHub ↗
({ children, allowedRoles }: { children: React.ReactNode; allowedRoles?: string[] })

Source from the content-addressed store, hash-verified

31
32// 受保护的路由组件
33const 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
47function App() {
48 const { isAuthenticated, user } = useAuthStore()

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected