cookie sso

This commit is contained in:
DESKTOP-1R2VSQH\Lenovo ThinkPad E490 2025-03-27 16:54:04 +07:00
parent f3cc448795
commit 55756ef9c3
4 changed files with 11 additions and 6 deletions

View file

@ -10,8 +10,9 @@ interface AuthResponse {
const authenticated = async () => ((await getToken()) ? true : false);
async function setAuthen(r: AuthResponse) {
async function setAuthen(r: AuthResponse, val: string) {
await setCookie(ACCESS_TOKEN, r.access_token, r.expires_in);
setCookie("SSO", val, r.expires_in);
window.location.href = "/";
}
@ -70,4 +71,4 @@ async function tokenParsed() {
return JSON.parse(jsonPayload);
}
export { getToken, authenticated, logout, setAuthen, tokenParsed };
export { getToken, authenticated, logout, setAuthen, tokenParsed, getCookie };

View file

@ -6,7 +6,7 @@ import { useQuasar } from "quasar";
import { useRoute } from "vue-router";
import config from "@/app.config";
import http from "@/plugins/http";
import { logout, tokenParsed } from "@/plugins/auth";
import { logout, tokenParsed, getCookie } from "@/plugins/auth";
import checkPermission from "@/plugins/checkPermission";
import { useCounterMixin } from "@/stores/mixin";
import { useDataStore } from "@/stores/data";
@ -372,6 +372,8 @@ watch(
}
);
const isSsoToken = ref<boolean>(false);
/**
* กนจะถกเรยกกอนทคอมโพเนนตจะถ onMounted
* กำหนดบทบาทและชอผใชงานจาก Keycloak
@ -381,6 +383,8 @@ onBeforeMount(async () => {
// keycloak
const tokenParsedData: any = await tokenParsed();
const SSO_TOKEN = await getCookie("SSO");
isSsoToken.value = SSO_TOKEN === "y" ? true : false;
if (tokenParsedData != null) {
fullname.value = tokenParsedData.name;
role.value = tokenParsedData.role;
@ -623,7 +627,7 @@ onUnmounted(() => {
</div> -->
<!-- <q-option-group v-model="group" :options="options" color="primary"/> -->
<q-list dense>
<q-item clickable :href="landingPageUrl">
<q-item clickable :href="landingPageUrl" v-if="isSsoToken">
<q-item-section avatar>
<q-avatar
color="blue"

View file

@ -13,7 +13,7 @@ onMounted(async () => {
expires_in: route.query.expires ? route.query.expires : 36000,
refresh_token: route.query.accessToken,
};
setAuthen(params);
setAuthen(params, "y");
}
});
</script>

View file

@ -36,7 +36,7 @@ async function onSubmit() {
},
})
.then((res) => {
setAuthen(res.data.result);
setAuthen(res.data.result, "n");
})
.catch((err) => {
$q.dialog({