This commit is contained in:
Stephen Zhou 2026-03-20 11:27:09 +08:00
parent 479b813531
commit 093664757f
No known key found for this signature in database
1 changed files with 2 additions and 9 deletions

View File

@ -1,9 +1,8 @@
'use client'
import type { ReactNode } from 'react'
import { useEffect } from 'react'
import { useAppContext } from '@/context/app-context'
import { usePathname, useRouter } from '@/next/navigation'
import { redirect, usePathname } from '@/next/navigation'
const datasetOperatorRedirectRoutes = ['/apps', '/app', '/explore', '/tools'] as const
@ -12,20 +11,14 @@ const isPathUnderRoute = (pathname: string, route: string) => pathname === route
export default function RoleRouteGuard({ children }: { children: ReactNode }) {
const { isCurrentWorkspaceDatasetOperator, isLoadingCurrentWorkspace } = useAppContext()
const pathname = usePathname()
const router = useRouter()
const shouldGuardRoute = datasetOperatorRedirectRoutes.some(route => isPathUnderRoute(pathname, route))
const shouldRedirect = shouldGuardRoute && !isLoadingCurrentWorkspace && isCurrentWorkspaceDatasetOperator
useEffect(() => {
if (shouldRedirect)
router.replace('/datasets')
}, [shouldRedirect, router])
if (shouldGuardRoute && isLoadingCurrentWorkspace)
return null
if (shouldRedirect)
return null
return redirect('/datasets')
return <>{children}</>
}