Skip to content

Commit a2c1ec0

Browse files
fix: Fixed white screen issue when regular users access restricted menus
1 parent 1751387 commit a2c1ec0

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

frontend/src/router/watch.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ const userStore = useUserStore()
1212
const { wsCache } = useCache()
1313
const whiteList = ['/login', '/admin-login']
1414
const assistantWhiteList = ['/assistant', '/embeddedPage', '/embeddedCommon', '/401']
15+
16+
const wsAdminRouterList = ['/ds/index', '/as/index']
1517
export const watchRouter = (router: Router) => {
1618
router.beforeEach(async (to: any, from: any, next: any) => {
1719
await loadXpackStatic()
@@ -35,14 +37,15 @@ export const watchRouter = (router: Router) => {
3537
next(toLoginPage(to.fullPath))
3638
return
3739
}
38-
let isFirstDynamicPath = false
3940
if (!userStore.getUid) {
4041
await userStore.info()
4142
generateDynamicRouters(router)
42-
isFirstDynamicPath = to?.path && ['/ds/index', '/as/index'].includes(to.path)
43+
const isFirstDynamicPath = to?.path && ['/ds/index', '/as/index'].includes(to.path)
4344
if (isFirstDynamicPath) {
44-
next({ ...to, replace: true })
45-
return
45+
if (userStore.isSpaceAdmin) {
46+
next({ ...to, replace: true })
47+
return
48+
}
4649
}
4750
}
4851
if (to.path === '/' || accessCrossPermission(to)) {
@@ -62,9 +65,14 @@ const accessCrossPermission = (to: any) => {
6265
if (!to?.path) return false
6366
return (
6467
(to.path.startsWith('/system') && !userStore.isAdmin) ||
65-
(to.path.startsWith('/set') && !userStore.isSpaceAdmin)
68+
(to.path.startsWith('/set') && !userStore.isSpaceAdmin) ||
69+
(isWsAdminRouter(to) && !userStore.isSpaceAdmin)
6670
)
6771
}
72+
73+
const isWsAdminRouter = (to?: any) => {
74+
return wsAdminRouterList.some((item: string) => to?.path?.startsWith(item))
75+
}
6876
const loadXpackStatic = () => {
6977
if (document.getElementById('sqlbot_xpack_static')) {
7078
return Promise.resolve()

0 commit comments

Comments
 (0)