diff --git a/src/views/home.vue b/src/views/home.vue index 1c6d09d..0cb1afe 100644 --- a/src/views/home.vue +++ b/src/views/home.vue @@ -161,22 +161,20 @@ onMounted(async () => { deleteCookie("BMAHRISCKI_KEYCLOAK_IDENTITY"); deleteCookie("BMAHRISUSER_KEYCLOAK_IDENTITY"); - const checkToken = await getCookie(cookieTokenName.value); - - if (!checkToken && !token.value) { - await axios - .post( - `${config.API.sso}/kcauth`, - {}, - { - headers: { - "Content-Type": "application/json", - }, - withCredentials: true, // Include cookies with the request - } - ) - .then(async (res: any) => { - if (res.status === 200) { + await axios + .post( + `${config.API.sso}/kcauth`, + {}, + { + 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); @@ -185,15 +183,16 @@ onMounted(async () => { // ยิง 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) => { - router.push("/sso"); - }); - } else { - token.value = await getCookie(cookieTokenName.value); - refreshToken.value = await getCookie(cookieTokenRefName.value); - } + } + }) + .catch((err: any) => { + router.push("/sso"); + }); + getName(); });