fixing check token

This commit is contained in:
Warunee Tamkoo 2024-07-26 14:26:09 +07:00
parent 56aa900ea3
commit 1a8a380f24
7 changed files with 112 additions and 77 deletions

View file

@ -2,7 +2,7 @@ import { createRouter, createWebHistory } from "vue-router";
const MainLayout = () => import("@/views/MainLayout.vue");
const Dashboard = () => import("@/modules/01_dashboard/views/Dashboard.vue");
const TestPage = () => import("@/modules/01_dashboard/views/test.vue");
const Error404NotFound = () => import("@/views/Error404NotFound.vue");
const loginMain = () => import("@/views/login.vue");
import ModuleTransfer from "@/modules/02_transfer/router";
@ -38,15 +38,6 @@ const router = createRouter({
Key: [7],
},
},
{
path: "/test",
name: "test",
component: TestPage,
meta: {
Auth: true,
Key: [7],
},
},
...ModuleTransfer,
...ModuleRetire,
@ -63,22 +54,33 @@ const router = createRouter({
...ModulePortfolio,
],
},
{
// path: "/:catchAll(.*)*", // TODO: ใช้ pathMatch แทนตามในเอกสารแนะนำ คงไว้เผื่อจำเป็น
path: "/:pathMatch(.*)*",
component: Error404NotFound,
},
{
path: "/login",
name: "loginMain",
component: loginMain,
meta: {
Auth: false,
Key: [7],
},
},
{
path: "/auth",
name: "auth",
component: () => import("@/views/auth.vue"),
},
],
});
// authen with keycloak client
router.beforeEach((to, from, next) => {
if (keycloak.authenticated === undefined && to.meta.Auth) {
kcLogout();
if (to.meta.Auth) {
if (keycloak.authenticated === undefined && to.meta.Auth) {
kcLogout();
}
} else {
next();
}