Skip to content

Commit 9fbb028

Browse files
committed
perf[permission]: add the verification of roles
1 parent 9b5f016 commit 9fbb028

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

src/permission.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@ router.beforeEach((to, from, next) => {
3131
router.addRoutes(store.getters.addRouters) // 动态添加可访问路由表
3232
next({ ...to, replace: true }) // hack方法 确保addRoutes已完成 ,set the replace: true so the navigation will not leave a history record
3333
})
34-
}).catch(() => {
34+
}).catch((err) => {
3535
store.dispatch('FedLogOut').then(() => {
36-
Message.error('Verification failed, please login again')
37-
next({ path: '/login' })
36+
Message.error(err || 'Verification failed, please login again')
37+
next({ path: '/' })
3838
})
3939
})
4040
} else {

src/store/modules/user.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,13 @@ const user = {
6767
reject('error')
6868
}
6969
const data = response.data
70-
commit('SET_ROLES', data.roles)
70+
71+
if (data.roles && data.roles.length > 0) { // 验证返回的roles是否是一个非空数组
72+
commit('SET_ROLES', data.roles)
73+
} else {
74+
reject('getInfo: roles must be a non-null array !')
75+
}
76+
7177
commit('SET_NAME', data.name)
7278
commit('SET_AVATAR', data.avatar)
7379
commit('SET_INTRODUCTION', data.introduction)

0 commit comments

Comments
 (0)