check role
This commit is contained in:
parent
2a1e85f720
commit
28c91a3a81
3 changed files with 35 additions and 17 deletions
|
|
@ -15,7 +15,7 @@ const keycloak = new Keycloak(keycloakConfig);
|
|||
async function kcAuthen(access_token: string, refresh_token: string) {
|
||||
await setCookie(ACCESS_TOKEN, access_token, 1);
|
||||
await setCookie(REFRESH_TOKEN, refresh_token, 1);
|
||||
window.location.href = "/";
|
||||
window.location.href = "/login";
|
||||
}
|
||||
|
||||
async function kcLogout() {
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ import type {
|
|||
} from "../interface/request/main/main";
|
||||
import { menuList } from "../interface/request/main/main";
|
||||
import checkPermission from "@/plugins/checkPermission";
|
||||
|
||||
// import { useroleUserDataStore } from "@/stores/roleUser";
|
||||
|
||||
const { setVerticalScrollPosition } = scroll;
|
||||
|
|
@ -190,9 +191,6 @@ const activeBtn = () => {
|
|||
* ยังจับ boolean ผิด จึงต้อง set
|
||||
*/
|
||||
onMounted(async () => {
|
||||
// if (keycloak.tokenParsed) {
|
||||
// await fetchroleUser(keycloak.tokenParsed.role);
|
||||
// }
|
||||
await fetchmsgNoread();
|
||||
// await getDataNotification(1, "NOMAL");
|
||||
myEventHandler(null, false);
|
||||
|
|
|
|||
|
|
@ -6,25 +6,21 @@ import keycloak, { keycloakConfig, kcAuthen } from "@/plugins/keycloak";
|
|||
import { useRouter } from "vue-router";
|
||||
import { useQuasar } from "quasar";
|
||||
import { useCounterMixin } from "@/stores/mixin";
|
||||
import CustomComponent from "@/components/CustomDialog.vue";
|
||||
|
||||
const router = useRouter();
|
||||
const mixin = useCounterMixin();
|
||||
const $q = useQuasar(); //ใช้ noti quasar
|
||||
|
||||
const { showLoader, hideLoader, messageError } = mixin;
|
||||
|
||||
function setCookie(name: string, value: any, days: number) {
|
||||
let expires = "";
|
||||
if (days) {
|
||||
const date = new Date();
|
||||
date.setTime(date.getTime() + days * 24 * 60 * 60 * 1000);
|
||||
expires = "; expires=" + date.toUTCString();
|
||||
}
|
||||
document.cookie = name + "=" + (value || "") + expires + "; path=/";
|
||||
}
|
||||
const isDisplay = ref<boolean>(true); // check display login page
|
||||
|
||||
const username = ref<string>("");
|
||||
const password = ref<string>("");
|
||||
|
||||
/**
|
||||
* @description ฟังก์ชั่นเข้าสู่ระบบ
|
||||
*/
|
||||
async function onSubmit() {
|
||||
showLoader();
|
||||
const formdata = new URLSearchParams();
|
||||
|
|
@ -60,15 +56,39 @@ async function onSubmit() {
|
|||
}
|
||||
|
||||
onMounted(() => {
|
||||
// check authen keycloak and role of system
|
||||
if (keycloak.authenticated) {
|
||||
console.log("authenticated", keycloak.authenticated);
|
||||
router.push("/");
|
||||
isDisplay.value = false;
|
||||
showLoader();
|
||||
if (keycloak.tokenParsed) {
|
||||
const checkRole = (element: string) =>
|
||||
element === "ADMIN" || element === "SUPER_ADMIN";
|
||||
|
||||
// ถ้าไม่มีสิทธิ์เข้าใช้งานระบบ แสดงข้อความแจ้งเตือน
|
||||
if (keycloak.tokenParsed.role.findIndex(checkRole) === -1) {
|
||||
$q.dialog({
|
||||
component: CustomComponent,
|
||||
componentProps: {
|
||||
title: "ข้อความแจ้งเตือน",
|
||||
message: "ขออภัยคุณไม่มีสิทธิ์เข้าใช้งานระบบนี้",
|
||||
icon: "warning",
|
||||
color: "red",
|
||||
onlycancel: true,
|
||||
},
|
||||
});
|
||||
hideLoader();
|
||||
isDisplay.value = true;
|
||||
} else {
|
||||
// ถ้ามีสิทธิ์เข้าใช้งานระบบ พาไปหน้าหลัก
|
||||
router.push("/");
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="bg-image">
|
||||
<div v-if="isDisplay" class="bg-image">
|
||||
<div class="login-pf-page">
|
||||
<div id="kc-logo">
|
||||
<div id="myimage"></div>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue