updated sso

This commit is contained in:
Warunee Tamkoo 2024-07-16 21:27:39 +07:00
parent 06b0e1dcbd
commit 6538140333
6 changed files with 111 additions and 94 deletions

View file

@ -9,8 +9,8 @@ const router = createRouter({
history: createWebHistory(import.meta.env.BASE_URL),
routes: [
{
path: "/",
name: "home",
path: '/',
name: 'home',
component: MianView,
children: [
{
@ -54,9 +54,9 @@ const router = createRouter({
// component: () => import('@/views/SampleCamera.vue'),
// },
/**
* 404 Not Found
* ref: https://router.vuejs.org/guide/essentials/dynamic-matching.html#catch-all-404-not-found-route
*/
* 404 Not Found
* ref: https://router.vuejs.org/guide/essentials/dynamic-matching.html#catch-all-404-not-found-route
*/
{
path: '/:pathMatch(.*)*',
name: 'NotFound',
@ -65,32 +65,32 @@ const router = createRouter({
Auth: true,
},
},
]
],
},
],
})
router.beforeEach((to, from, next) => {
if (to.meta.Auth) {
if (!keycloak.authenticated) {
keycloak.login({
redirectUri: `${window.location.protocol}//${window.location.host}${to.path}`,
locale: 'th',
})
} else {
// keycloak.updateToken(60);
// const role = keycloak.tokenParsed?.role
// if (role.includes(to.meta.Role)) {
next()
// } else {
// next({ path: '' })
// // next();
// }
console.log('keycloak===>', keycloak)
console.log('keycloak authenticated===>', keycloak.authenticated)
if (keycloak.authenticated === undefined) {
window.location.href = 'https://bma-sso.frappet.synology.me'
// } else {
// // keycloak.updateToken(60);
// // const role = keycloak.tokenParsed?.role
// // if (role.includes(to.meta.Role)) {
// next()
// // } else {
// // next({ path: '' })
// // // next();
// // }
}
} else {
next()
}
// next();
next()
})
export default router