From bb158a9765cd6e6a732344f57d794b144e6ae45b Mon Sep 17 00:00:00 2001 From: waruneeauy Date: Wed, 28 Aug 2024 16:37:46 +0700 Subject: [PATCH] fixing router --- src/router/index.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/router/index.ts b/src/router/index.ts index 1f40b9a..247aa3c 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -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()