This commit is contained in:
DESKTOP-1R2VSQH\Lenovo ThinkPad E490 2024-07-24 17:57:06 +07:00
parent c97bbc7a78
commit 7b3a4c18ba
9 changed files with 406 additions and 47 deletions

View file

@ -3,6 +3,7 @@ import { createRouter, createWebHistory } from "vue-router";
const MainLayout = () => import("@/views/MainLayout.vue");
const Dashboard = () => import("@/views/Dashboard.vue");
const Error404NotFound = () => import("@/views/Error404NotFound.vue");
const loginView = () => import("@/views/login.vue");
import ModuleMetadata from "@/modules/01_metadata/router";
import ModuleUser from "@/modules/02_users/router";
@ -34,7 +35,7 @@ const router = createRouter({
...ModuleMetadata,
...ModuleUser,
...ModuleLogs,
...ModuleSystem
...ModuleSystem,
],
},
/**
@ -46,6 +47,16 @@ const router = createRouter({
path: "/:pathMatch(.*)*",
component: Error404NotFound,
},
// authen with keycloak client
{
path: "/login",
name: "loginMain",
component: loginView,
meta: {
Auth: false,
},
},
],
scrollBehavior(to, from, savedPosition) {
@ -60,25 +71,16 @@ const router = createRouter({
},
});
// authen with keycloak client
router.beforeEach((to, from, next) => {
if (to.meta.Auth) {
if (!keycloak.authenticated) {
keycloak.login({
redirectUri: `${window.location.protocol}//${window.location.host}${to.path}`,
locale: "th",
});
} else {
// keycloak.updateToken(60);
// if (checkPermission(to.meta.Role)) {
next();
// } else {
// next({ path: "" });
// }
if (keycloak.authenticated === undefined && to.meta.Auth) {
window.location.href = "/login";
}
} else {
next();
}
// next();
next();
});
export default router;