fixing auth

This commit is contained in:
Warunee Tamkoo 2024-07-26 12:52:47 +07:00
parent f4592d2844
commit 3c4202a928
7 changed files with 91 additions and 102 deletions

View file

@ -28,7 +28,7 @@ import ModuleSupport from "@/modules/00_support/router";
import ModuleActing from "@/modules/17_acting/router";
// TODO: ใช้หรือไม่?
import keycloak from "@/plugins/keycloak";
import keycloak, { kcLogout } from "@/plugins/keycloak";
const router = createRouter({
history: createWebHistory(import.meta.env.BASE_URL),
@ -91,6 +91,11 @@ const router = createRouter({
Key: [7],
},
},
{
path: "/auth",
name: "auth",
component: () => import("@/views/auth.vue"),
},
],
scrollBehavior(to, from, savedPosition) {
@ -108,8 +113,10 @@ const router = createRouter({
// authen with keycloak client
router.beforeEach((to, from, next) => {
if (to.meta.Auth) {
if (keycloak.authenticated === undefined && to.meta.Auth) {
window.location.href = "/login";
if (keycloak.authenticated === undefined) {
kcLogout();
} else {
next();
}
} else {
next();