api saveLog

This commit is contained in:
DESKTOP-1R2VSQH\Lenovo ThinkPad E490 2024-12-18 10:11:48 +07:00
parent 146dcb9028
commit 3f5b7356f1
2 changed files with 42 additions and 6 deletions

View file

@ -1,7 +1,8 @@
import env from "./index";
const org = `${env.API_URI}/org`;
// const log = `${env.API_URI}/log`;
const ssoLog = `${env.API_URI}/org/keycloak/log/sso`;
export default {
org,
ssoLog,
};

View file

@ -13,6 +13,7 @@ import screen3 from "@/assets/screen3.png";
import screen4 from "@/assets/screen4.png";
import type { DateCards } from "@/interface/index/Main";
import http from "@/plugins/http";
const $q = useQuasar();
@ -109,11 +110,44 @@ async function goPage(sys: string, url: string) {
}
async function logout() {
await deleteCookie("BMAHRIS_KEYCLOAK_IDENTITY");
await deleteCookie("BMAHRIS_KEYCLOAK_REFRESH");
$q.dialog({
component: CustomComponent,
componentProps: {
title: `ยืนยันการออกจากระบบ`,
message: "ต้องการออกจากระบบใช่หรือไม่?",
icon: "info",
color: "public",
},
cancel: true,
persistent: true,
}).onOk(async () => {
await deleteCookie("BMAHRIS_KEYCLOAK_IDENTITY");
await deleteCookie("BMAHRIS_KEYCLOAK_REFRESH");
// logout
await postSaveLog("ออกจากระบบ", token.value);
window.location.href = `${config.API.URL_SSO}`;
});
}
// logout
window.location.href = `${config.API.URL_SSO}`;
async function postSaveLog(type: string, token: any) {
await axios
.post(
config.API.ssoLog,
{ text: type },
{
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${token}`,
accept: "application/json",
},
}
)
.then((res) => {
console.log("res:", res.data);
})
.catch((err) => {
console.error("Error:", err);
});
}
onMounted(async () => {
@ -138,11 +172,12 @@ onMounted(async () => {
withCredentials: true, // Include cookies with the request
}
)
.then((res: any) => {
.then(async (res: any) => {
if (res.status === 200) {
setCookie("BMAHRIS_KEYCLOAK_IDENTITY", res.data.access_token, 1);
setCookie("BMAHRIS_KEYCLOAK_REFRESH", res.data.refresh_token, 1);
// log
await postSaveLog("เข้าสู่ระบบ", res.data.access_token);
}
})
.catch((err: any) => {