update auth

This commit is contained in:
DESKTOP-1R2VSQH\Lenovo ThinkPad E490 2024-08-28 15:14:19 +07:00
parent abeb6ca085
commit 3c36acbba1
10 changed files with 223 additions and 161 deletions

View file

@ -11,7 +11,7 @@ import ModuleLogs from "@/modules/03_logs/router";
import ModuleSystem from "@/modules/04_system/router";
// TODO: ใช้หรือไม่?
import keycloak, { kcLogout } from "@/plugins/keycloak";
import { authenticated, logout } from "@/plugins/auth";
const router = createRouter({
history: createWebHistory(import.meta.env.BASE_URL),
@ -76,10 +76,11 @@ const router = createRouter({
});
// authen with keycloak client
router.beforeEach((to, from, next) => {
router.beforeEach(async (to, from, next) => {
if (to.meta.Auth) {
if (keycloak.authenticated === undefined && to.meta.Auth) {
kcLogout();
const checkAuthen = await authenticated();
if (!checkAuthen && to.meta.Auth) {
logout();
}
} else {
next();