cookie sso
This commit is contained in:
parent
75fa420862
commit
ee2610fa54
4 changed files with 11 additions and 6 deletions
|
|
@ -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 };
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ import { storeToRefs } from "pinia";
|
|||
import { scroll, useQuasar } from "quasar";
|
||||
import { useCounterMixin } from "@/stores/mixin";
|
||||
import { useMenuDataStore } from "@/stores/menuList";
|
||||
import { tokenParsed, logout } from "@/plugins/auth";
|
||||
import { tokenParsed, logout, getCookie } from "@/plugins/auth";
|
||||
import avatar from "@/assets/avatar_user.jpg";
|
||||
|
||||
import http from "@/plugins/http";
|
||||
|
|
@ -232,6 +232,8 @@ const activeBtn = () => {
|
|||
return route.name == "registryDetail" && rightActive.value;
|
||||
};
|
||||
|
||||
const isSsoToken = ref<boolean>(false);
|
||||
|
||||
/**
|
||||
* เมื่อเริ่มต้นโปรแกรมให้ฟัง event resize และ function myEventHandler
|
||||
* set function myEventHandler เพราะ state ยังไม่เซ็ท , state เซ็ทเมื่อ หน้าจอเริ่ม ขยับหน้าจอ
|
||||
|
|
@ -246,6 +248,8 @@ onMounted(async () => {
|
|||
fetchKeycloakPosition();
|
||||
|
||||
const user = await tokenParsed();
|
||||
const SSO_TOKEN = await getCookie("SSO");
|
||||
isSsoToken.value = SSO_TOKEN === "y" ? true : false;
|
||||
if (user) {
|
||||
fullname.value = user.name;
|
||||
role.value = user.role;
|
||||
|
|
@ -775,7 +779,7 @@ function onViewDetailNoti(url: string) {
|
|||
เลือกโหมด
|
||||
</div> -->
|
||||
<q-list dense>
|
||||
<q-item clickable :href="landingPageUrl">
|
||||
<q-item clickable :href="landingPageUrl" v-if="isSsoToken">
|
||||
<q-item-section avatar>
|
||||
<q-avatar
|
||||
color="blue"
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ onMounted(async () => {
|
|||
expires_in: route.query.expires ? route.query.expires : 36000,
|
||||
refresh_token: route.query.accessToken,
|
||||
};
|
||||
setAuthen(params);
|
||||
setAuthen(params, "y");
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ async function onSubmit() {
|
|||
},
|
||||
})
|
||||
.then(async (res) => {
|
||||
setAuthen(res.data.result);
|
||||
setAuthen(res.data.result, "n");
|
||||
})
|
||||
.catch((err) => {
|
||||
$q.dialog({
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue