Skip to content

Commit

Permalink
fix(front-permission): 修复前端权限检查时如果值为空对象时:{},进入判断条件,导致显示无权限
Browse files Browse the repository at this point in the history
  • Loading branch information
kanyxmo committed Nov 19, 2024
1 parent 3efad49 commit 333d41b
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions web/src/router/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import '@/assets/styles/nprogress.scss'
import hasAuth from '@/utils/permission/hasAuth.ts'
import hasRole from '@/utils/permission/hasRole.ts'
import hasUser from '@/utils/permission/hasUser.ts'
import { isEmpty } from 'radash'

const { isLoading } = useNProgress()

Expand Down Expand Up @@ -53,16 +54,19 @@ router.afterEach(async (to) => {
isLoading.value = false
const keepAliveStore = useKeepAliveStore()

if (to.meta.auth && !hasAuth(to.meta.auth as string[])) {
if (!isEmpty(to.meta.auth) && !hasAuth(to.meta.auth as string[])) {
await router.push({ path: '/403' })
return
}

if (to.meta.role && !hasRole(to.meta.role as string[])) {
if (!isEmpty(to.meta.role) && !hasRole(to.meta.role as string[])) {
await router.push({ path: '/403' })
return
}

if (to.meta.user && !hasUser(to.meta.user as string[])) {
if (!isEmpty(to.meta.user) && !hasUser(to.meta.user as string[])) {
await router.push({ path: '/403' })
return
}

if (to.meta.cache) {
Expand Down

0 comments on commit 333d41b

Please sign in to comment.