add login keycloak

This commit is contained in:
Kittapath 2023-08-08 14:03:12 +07:00
parent 4b73b98d35
commit 6c3c9384d9
12 changed files with 457 additions and 292 deletions

View file

@ -6,6 +6,9 @@ const Dashboard = () => import("@/modules/01_dashboard/views/Dashboard.vue")
import ModuleTransfer from "@/modules/02_transfer/router.ts"
import ModuleLeave from "@/modules/03_leave/router.ts"
// TODO: ใช้หรือไม่?
import keycloak from "@/plugins/keycloak"
const router = createRouter({
history: createWebHistory(import.meta.env.BASE_URL),
routes: [
@ -18,6 +21,10 @@ const router = createRouter({
path: "/",
name: "dashboard",
component: Dashboard,
meta: {
Auth: true,
Key: [7],
},
},
...ModuleTransfer,
...ModuleLeave,
@ -26,4 +33,20 @@ const router = createRouter({
],
})
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 {
next()
}
} else {
next()
}
// next();
})
export default router