From 3dfc3205bbf4067059e45109bef2392720810706 Mon Sep 17 00:00:00 2001 From: waruneeauy Date: Thu, 13 Mar 2025 17:24:09 +0700 Subject: [PATCH] fixing layout and uid for dev --- src/api/index.ts | 2 +- src/views/home.vue | 79 ++++++++++++++++++++++++---------------------- src/views/sso.vue | 4 +-- vite.config.js | 2 +- 4 files changed, 46 insertions(+), 41 deletions(-) diff --git a/src/api/index.ts b/src/api/index.ts index 224c1e8..76e1ab6 100644 --- a/src/api/index.ts +++ b/src/api/index.ts @@ -17,7 +17,7 @@ export const urlSSO = import.meta.env.VITE_URL_SSO; const config = ref({ development: { // API_URI: "https://localhost:7260/api", - API_URI: "https://hrms.chin.in.th/api/v1", + API_URI: "http://localhost:3001/api/v1", API_SSO: "http://localhost:3001/api/v1/sso", URL_ADMIN: urlAdmin, URL_USER: urlUser, diff --git a/src/views/home.vue b/src/views/home.vue index 1b6bb96..8b6e824 100644 --- a/src/views/home.vue +++ b/src/views/home.vue @@ -183,44 +183,49 @@ onMounted(async () => { deleteCookie("BMAHRISUSER_KEYCLOAK_IDENTITY"); const uid = route.query.uid?.toString() || getCookie("uid"); - const serve = location.hostname == "hrms.bangkok.go.th" ? "sso" : "uat"; - await axios - .post( - `${config.API.sso}/kcauth`, - { uid, serve }, - { - headers: { - "Content-Type": "application/json", - }, - withCredentials: true, // Include cookies with the request - } - ) - .then(async (res: any) => { - if (res.status === 200) { - if (res.data.access_token) { - setCookie(cookieTokenName.value, res.data.access_token, 1); - setCookie(cookieTokenRefName.value, res.data.refresh_token, 1); - - token.value = await res.data.access_token; - refreshToken.value = await res.data.refresh_token; - - // ยิง log เข้าระบบ - await postSaveLog("เข้าสู่ระบบ", res.data.access_token); - } else if (res.data.isLogin) { - token.value = await getCookie(cookieTokenName.value); - refreshToken.value = await getCookie(cookieTokenRefName.value); + if (uid) { + // ยิงไปตรวจสอบ token ที่ได้จาก cookie หรือจาก url แล้วเก็บไว้ใน cookie + await axios + .post( + `${config.API.sso}/kcauth`, + { uid }, + { + headers: { + "Content-Type": "application/json", + }, + withCredentials: true, // Include cookies with the request } - } - }) - .catch((err: any) => { - if (location.hostname != "hrms.bangkok.go.th") { - router.push("/sso"); - } else { - window.location.href = `${config.API.URL_SSO}`; - } - }); + ) + .then(async (res: any) => { + if (res.status === 200) { + if (res.data.access_token) { + setCookie(cookieTokenName.value, res.data.access_token, 1); + setCookie(cookieTokenRefName.value, res.data.refresh_token, 1); + setCookie("uid", uid, 1); - getName(); + token.value = await res.data.access_token; + refreshToken.value = await res.data.refresh_token; + + // ยิง log เข้าระบบ + await postSaveLog("เข้าสู่ระบบ", res.data.access_token); + } else if (res.data.isLogin) { + token.value = await getCookie(cookieTokenName.value); + refreshToken.value = await getCookie(cookieTokenRefName.value); + } + } + }) + .catch((err: any) => { + deleteCookie("uid"); + if (location.hostname != "hrms.bangkok.go.th") { + router.push("/sso"); + } else { + window.location.href = `${config.API.URL_SSO}`; + } + }); + + // ดึงชื่อผู้ใช้ + getName(); + } }); @@ -231,7 +236,7 @@ onMounted(async () => {
-
+
diff --git a/src/views/sso.vue b/src/views/sso.vue index 81bcc6e..8da35bb 100644 --- a/src/views/sso.vue +++ b/src/views/sso.vue @@ -43,8 +43,8 @@ async function onSubmit() { } ) .then(async (res) => { - if (res.data === "OK") { - await setCookie("uid", username.value, 1); + if (res.data.uid) { + await setCookie("uid", res.data.uid, 1); router.push("/"); } }) diff --git a/vite.config.js b/vite.config.js index c05dc72..4835f61 100644 --- a/vite.config.js +++ b/vite.config.js @@ -26,7 +26,7 @@ export default defineConfig({ }, includeAssets: ['icons/safari-pinned-tab.svg'], manifest: { - name: 'BMA-Checkin', + name: 'HRMS-Checkin', short_name: 'EHR Checkin', theme_color: '#ffffff', },