fixing check sso

This commit is contained in:
Warunee Tamkoo 2024-12-20 11:00:59 +07:00
parent e37934c9f2
commit 8dd852aeeb

View file

@ -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();
});
</script>