refactor: add roles admin and user
This commit is contained in:
parent
72888c407e
commit
a28bc7de6b
3 changed files with 59 additions and 29 deletions
|
|
@ -10,6 +10,26 @@ const router = createRouter({
|
|||
path: '/',
|
||||
name: 'UserModule',
|
||||
component: () => import('@/views/MainLayout.vue'),
|
||||
beforeEnter: (_to, _from, next) => {
|
||||
const token = KeyCloakService.GetAccesToken()
|
||||
if (token) {
|
||||
next()
|
||||
} else {
|
||||
KeyCloakService.CallLogin(() => {
|
||||
const tokenAfterLogin = KeyCloakService.GetAccesToken()
|
||||
const roles = KeyCloakService.GetUserRoles()
|
||||
console.log(roles);
|
||||
|
||||
|
||||
if (tokenAfterLogin && (roles.includes('user') || roles.includes('admin')) ) {
|
||||
next()
|
||||
} else {
|
||||
console.error('ไม่สามารถดึง Token หลังจากล็อกอินได้')
|
||||
next('/')
|
||||
}
|
||||
})
|
||||
}
|
||||
},
|
||||
children: [...UserModule],
|
||||
meta: {
|
||||
statusAccount: false,
|
||||
|
|
@ -26,7 +46,11 @@ const router = createRouter({
|
|||
} else {
|
||||
KeyCloakService.CallLogin(() => {
|
||||
const tokenAfterLogin = KeyCloakService.GetAccesToken()
|
||||
if (tokenAfterLogin) {
|
||||
const roles = KeyCloakService.GetUserRoles()
|
||||
console.log(roles);
|
||||
|
||||
|
||||
if (tokenAfterLogin && roles.includes('admin') ) {
|
||||
next()
|
||||
} else {
|
||||
console.error('ไม่สามารถดึง Token หลังจากล็อกอินได้')
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue