fixing router

This commit is contained in:
Warunee Tamkoo 2024-08-28 16:37:46 +07:00
parent bc5bae34aa
commit bb158a9765

View file

@ -4,7 +4,7 @@ import MapView from '@/views/MapView.vue'
import MainView from '@/views/MainView.vue'
const loginView = () => import('@/views/login.vue')
import { authenticated, logout } from '@/plugins/auth'
import { authenticated } from '@/plugins/auth'
const router = createRouter({
history: createWebHistory(import.meta.env.BASE_URL),
@ -81,10 +81,11 @@ const router = createRouter({
})
// authen with keycloak client
router.beforeEach((to, from, next) => {
router.beforeEach(async (to, from, next) => {
if (to.meta.Auth) {
if (authenticated === undefined && to.meta.Auth) {
logout()
const checkAuthen = await authenticated()
if (!checkAuthen && to.meta.Auth) {
router.push({ name: 'loginMain' })
}
} else {
next()