cookie sso
This commit is contained in:
parent
0f2a0cf784
commit
a9f1bbd1dc
2 changed files with 18 additions and 7 deletions
|
|
@ -15,14 +15,20 @@ const authenticated = async () => ((await getToken()) ? true : false)
|
||||||
|
|
||||||
async function setAuthen(r: AuthResponse) {
|
async function setAuthen(r: AuthResponse) {
|
||||||
await setCookie(ACCESS_TOKEN, r.access_token, r.expires_in)
|
await setCookie(ACCESS_TOKEN, r.access_token, r.expires_in)
|
||||||
|
await setCookieSso('y', r)
|
||||||
window.location.href = '/'
|
window.location.href = '/'
|
||||||
}
|
}
|
||||||
|
|
||||||
async function setAuthenCheckin(r: AuthResponse) {
|
async function setAuthenCheckin(r: AuthResponse) {
|
||||||
await setCookieCheckin(ACCESS_TOKEN, r.access_token, r.expires_in)
|
await setCookieCheckin(ACCESS_TOKEN, r.access_token, r.expires_in)
|
||||||
|
await setCookieSso('n', r)
|
||||||
window.location.href = '/'
|
window.location.href = '/'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function setCookieSso(val: string, r: AuthResponse) {
|
||||||
|
setCookie('SSO', val, r.expires_in)
|
||||||
|
}
|
||||||
|
|
||||||
async function logout() {
|
async function logout() {
|
||||||
await deleteCookie(ACCESS_TOKEN)
|
await deleteCookie(ACCESS_TOKEN)
|
||||||
// window.location.href = key_C_Config.url_Logout
|
// window.location.href = key_C_Config.url_Logout
|
||||||
|
|
@ -92,6 +98,7 @@ async function tokenParsed() {
|
||||||
}
|
}
|
||||||
|
|
||||||
export {
|
export {
|
||||||
|
getCookie,
|
||||||
getToken,
|
getToken,
|
||||||
authenticated,
|
authenticated,
|
||||||
logout,
|
logout,
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ import { useRouter } from 'vue-router'
|
||||||
import http from '@/plugins/http'
|
import http from '@/plugins/http'
|
||||||
import config from '@/app.config'
|
import config from '@/app.config'
|
||||||
import avatar from '@/assets/avatar_user.jpg'
|
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 { useCounterMixin } from '@/stores/mixin'
|
||||||
|
|
||||||
import type { notiType } from '@/interface/index/Main'
|
import type { notiType } from '@/interface/index/Main'
|
||||||
|
|
@ -27,9 +27,9 @@ const router = useRouter()
|
||||||
const $q = useQuasar()
|
const $q = useQuasar()
|
||||||
|
|
||||||
// landing page config url
|
// landing page config url
|
||||||
// const configParam = {
|
const configParam = {
|
||||||
// landingPageUrl: import.meta.env.VITE_URL_LANDING,
|
landingPageUrl: import.meta.env.VITE_URL_LANDING,
|
||||||
// }
|
}
|
||||||
|
|
||||||
const modalReset = ref<boolean>(false) //ตัวแปร popup reset password
|
const modalReset = ref<boolean>(false) //ตัวแปร popup reset password
|
||||||
const fullName = ref<string>('') //ชื่อผู้ใช้งาน
|
const fullName = ref<string>('') //ชื่อผู้ใช้งาน
|
||||||
|
|
@ -160,7 +160,7 @@ function onLoad(index: number, done: Function) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// landing page redirect
|
// landing page redirect
|
||||||
// const landingPageUrl = ref<string>(configParam.landingPageUrl)
|
const landingPageUrl = ref<string>(configParam.landingPageUrl)
|
||||||
|
|
||||||
/** ฟังก์ชันเรียกข้อมูลผู้ใช่งาน*/
|
/** ฟังก์ชันเรียกข้อมูลผู้ใช่งาน*/
|
||||||
async function fetchKeycloakPosition() {
|
async function fetchKeycloakPosition() {
|
||||||
|
|
@ -284,10 +284,14 @@ function ruleReNewPassWord(val: string) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const isSsoToken = ref<boolean>(false)
|
||||||
|
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
fetchTotolNotificate()
|
fetchTotolNotificate()
|
||||||
fetchKeycloakPosition()
|
fetchKeycloakPosition()
|
||||||
const checkTokenParsed = await tokenParsed()
|
const checkTokenParsed = await tokenParsed()
|
||||||
|
const SSO_TOKEN = await getCookie('SSO')
|
||||||
|
isSsoToken.value = SSO_TOKEN === 'y' ? true : false
|
||||||
if (checkTokenParsed != null) {
|
if (checkTokenParsed != null) {
|
||||||
fullName.value = checkTokenParsed.name
|
fullName.value = checkTokenParsed.name
|
||||||
}
|
}
|
||||||
|
|
@ -464,7 +468,7 @@ onMounted(async () => {
|
||||||
|
|
||||||
<q-separator />
|
<q-separator />
|
||||||
<q-list dense class="q-py-sm">
|
<q-list dense class="q-py-sm">
|
||||||
<!-- <q-item clickable :href="landingPageUrl">
|
<q-item clickable :href="landingPageUrl" v-if="isSsoToken">
|
||||||
<q-item-section avatar>
|
<q-item-section avatar>
|
||||||
<q-avatar
|
<q-avatar
|
||||||
color="blue"
|
color="blue"
|
||||||
|
|
@ -475,7 +479,7 @@ onMounted(async () => {
|
||||||
/>
|
/>
|
||||||
</q-item-section>
|
</q-item-section>
|
||||||
<q-item-section class="q-py-sm"> Landing Page </q-item-section>
|
<q-item-section class="q-py-sm"> Landing Page </q-item-section>
|
||||||
</q-item> -->
|
</q-item>
|
||||||
<q-item clickable @click="onreset()">
|
<q-item clickable @click="onreset()">
|
||||||
<q-item-section avatar>
|
<q-item-section avatar>
|
||||||
<q-avatar
|
<q-avatar
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue