diff --git a/src/plugins/auth.ts b/src/plugins/auth.ts index 5052942..0c171ea 100644 --- a/src/plugins/auth.ts +++ b/src/plugins/auth.ts @@ -15,14 +15,20 @@ const authenticated = async () => ((await getToken()) ? true : false) async function setAuthen(r: AuthResponse) { await setCookie(ACCESS_TOKEN, r.access_token, r.expires_in) + await setCookieSso('y', r) window.location.href = '/' } async function setAuthenCheckin(r: AuthResponse) { await setCookieCheckin(ACCESS_TOKEN, r.access_token, r.expires_in) + await setCookieSso('n', r) window.location.href = '/' } +async function setCookieSso(val: string, r: AuthResponse) { + setCookie('SSO', val, r.expires_in) +} + async function logout() { await deleteCookie(ACCESS_TOKEN) // window.location.href = key_C_Config.url_Logout @@ -92,6 +98,7 @@ async function tokenParsed() { } export { + getCookie, getToken, authenticated, logout, diff --git a/src/views/MainView.vue b/src/views/MainView.vue index 14df40d..69a6ec9 100644 --- a/src/views/MainView.vue +++ b/src/views/MainView.vue @@ -6,7 +6,7 @@ import { useRouter } from 'vue-router' import http from '@/plugins/http' import config from '@/app.config' import avatar from '@/assets/avatar_user.jpg' -import { logout, tokenParsed } from '@/plugins/auth' +import { logout, tokenParsed, getCookie } from '@/plugins/auth' import { useCounterMixin } from '@/stores/mixin' import type { notiType } from '@/interface/index/Main' @@ -27,9 +27,9 @@ const router = useRouter() const $q = useQuasar() // landing page config url -// const configParam = { -// landingPageUrl: import.meta.env.VITE_URL_LANDING, -// } +const configParam = { + landingPageUrl: import.meta.env.VITE_URL_LANDING, +} const modalReset = ref(false) //ตัวแปร popup reset password const fullName = ref('') //ชื่อผู้ใช้งาน @@ -160,7 +160,7 @@ function onLoad(index: number, done: Function) { } // landing page redirect -// const landingPageUrl = ref(configParam.landingPageUrl) +const landingPageUrl = ref(configParam.landingPageUrl) /** ฟังก์ชันเรียกข้อมูลผู้ใช่งาน*/ async function fetchKeycloakPosition() { @@ -284,10 +284,14 @@ function ruleReNewPassWord(val: string) { }) } +const isSsoToken = ref(false) + onMounted(async () => { fetchTotolNotificate() fetchKeycloakPosition() const checkTokenParsed = await tokenParsed() + const SSO_TOKEN = await getCookie('SSO') + isSsoToken.value = SSO_TOKEN === 'y' ? true : false if (checkTokenParsed != null) { fullName.value = checkTokenParsed.name } @@ -464,7 +468,7 @@ onMounted(async () => { - +