login
This commit is contained in:
parent
900d308f81
commit
6e2d5beee0
8 changed files with 426 additions and 42 deletions
|
|
@ -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 ModuleMetadataNew from "@/modules/01_metadataNew/router";
|
||||
|
|
@ -79,6 +80,17 @@ const router = createRouter({
|
|||
path: "/:pathMatch(.*)*",
|
||||
component: Error404NotFound,
|
||||
},
|
||||
|
||||
// authen with keycloak client
|
||||
{
|
||||
path: "/login",
|
||||
name: "loginMain",
|
||||
component: loginView,
|
||||
meta: {
|
||||
Auth: false,
|
||||
Key: [7],
|
||||
},
|
||||
},
|
||||
],
|
||||
|
||||
scrollBehavior(to, from, savedPosition) {
|
||||
|
|
@ -93,31 +105,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);
|
||||
const role = keycloak.tokenParsed?.role;
|
||||
|
||||
// ถ้าเป็นคนกรอกข้อมูล
|
||||
if (role.includes("keyregistry") && to.meta.Role != "registry") {
|
||||
next({ path: "/registry" });
|
||||
} else if (role.includes(to.meta.Role)) {
|
||||
next();
|
||||
} else {
|
||||
next({ path: "" });
|
||||
// next();
|
||||
}
|
||||
if (keycloak.authenticated === undefined && to.meta.Auth) {
|
||||
window.location.href = "/login";
|
||||
}
|
||||
} else {
|
||||
next();
|
||||
}
|
||||
// next();
|
||||
next();
|
||||
});
|
||||
|
||||
export default router;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue