MCPcopy Index your code
hub / github.com/FlowiseAI/Flowise / DefaultRedirect

Function DefaultRedirect

packages/ui/src/routes/DefaultRedirect.jsx:33–100  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

31 * This prevents 403 errors when users don't have access to the default chatflows page
32 */
33export const DefaultRedirect = () => {
34 const { hasPermission, hasDisplay } = useAuth()
35 const { isOpenSource } = useConfig()
36 const isGlobal = useSelector((state) => state.auth.isGlobal)
37 const isAuthenticated = useSelector((state) => state.auth.isAuthenticated)
38
39 // Define the order of routes to check (based on the menu order in dashboard.js)
40 const routesToCheck = [
41 { component: Chatflows, permission: 'chatflows:view' },
42 { component: Agentflows, permission: 'agentflows:view' },
43 { component: Executions, permission: 'executions:view' },
44 { component: Assistants, permission: 'assistants:view' },
45 { component: Marketplaces, permission: 'templates:marketplace,templates:custom' },
46 { component: Tools, permission: 'tools:view' },
47 { component: Credentials, permission: 'credentials:view' },
48 { component: Variables, permission: 'variables:view' },
49 { component: APIKey, permission: 'apikeys:view' },
50 { component: Documents, permission: 'documentStores:view' },
51 // Evaluation routes (with display flags)
52 { component: EvalDatasets, permission: 'datasets:view', display: 'feat:datasets' },
53 { component: Evaluators, permission: 'evaluators:view', display: 'feat:evaluators' },
54 { component: EvalEvaluation, permission: 'evaluations:view', display: 'feat:evaluations' },
55 // Management routes (with display flags)
56 { component: SSOConfig, permission: 'sso:manage', display: 'feat:sso-config' },
57 { component: RolesPage, permission: 'roles:manage', display: 'feat:roles' },
58 { component: UsersPage, permission: 'users:manage', display: 'feat:users' },
59 { component: Workspaces, permission: 'workspace:view', display: 'feat:workspaces' },
60 { component: LoginActivityPage, permission: 'loginActivity:view', display: 'feat:login-activity' },
61 // Other routes
62 { component: Logs, permission: 'logs:view', display: 'feat:logs' },
63 { component: Account, display: 'feat:account' }
64 ]
65
66 // If user is not authenticated, show login page
67 if (!isAuthenticated) {
68 return <Login />
69 }
70
71 // For open source, show chatflows (no permission checks)
72 if (isOpenSource) {
73 return <Chatflows />
74 }
75
76 // For global admins, show chatflows (they have access to everything)
77 if (isGlobal) {
78 return <Chatflows />
79 }
80
81 // Check each route in order and return the first accessible component
82 for (const route of routesToCheck) {
83 const { component: Component, permission, display } = route
84
85 // Check permission if specified
86 const hasRequiredPermission = !permission || hasPermission(permission)
87
88 // Check display flag if specified
89 const hasRequiredDisplay = !display || hasDisplay(display)
90

Callers

nothing calls this directly

Calls 4

useAuthFunction · 0.90
useConfigFunction · 0.90
hasPermissionFunction · 0.85
hasDisplayFunction · 0.85

Tested by

no test coverage detected