From a5fbf5c880bfdb04edc47e22eae8a3731824b4c2 Mon Sep 17 00:00:00 2001 From: waruneeauy Date: Fri, 16 Aug 2024 17:00:33 +0700 Subject: [PATCH] fixing check token auth --- src/plugins/http.ts | 4 +--- src/stores/mixin.ts | 19 +++++++++++++++++++ src/views/MainView.vue | 29 ++++++++++++++++------------- 3 files changed, 36 insertions(+), 16 deletions(-) diff --git a/src/plugins/http.ts b/src/plugins/http.ts index 33d37f8..b82f8c1 100644 --- a/src/plugins/http.ts +++ b/src/plugins/http.ts @@ -1,5 +1,5 @@ import Axios, { type AxiosRequestConfig, type AxiosResponse } from 'axios' -import keycloak, { kcLogout } from './keycloak' +import keycloak from './keycloak' const http = Axios.create({ timeout: 1000000000, // เพิ่มค่า timeout @@ -31,8 +31,6 @@ http.interceptors.response.use( // eslint-disable-next-line no-prototype-builtins if (error.hasOwnProperty('response')) { if (error.response.status === 401 || error.response.status === 403) { - kcLogout() - // Store.commit("SET_ERROR_MESSAGE", error.response.data.message); // Store.commit("REMOVE_ACCESS_TOKEN") } diff --git a/src/stores/mixin.ts b/src/stores/mixin.ts index 80dbd12..6516393 100644 --- a/src/stores/mixin.ts +++ b/src/stores/mixin.ts @@ -1,6 +1,7 @@ import { defineStore } from 'pinia' import CustomComponent from '@/components/CustomDialog.vue' import { Loading, QSpinnerCube } from 'quasar' +import { kcLogout } from '@/plugins/keycloak' export const useCounterMixin = defineStore('mixin', () => { function date2Thai(srcDate: Date, isFullMonth = false, isTime = false) { @@ -143,6 +144,12 @@ export const useCounterMixin = defineStore('mixin', () => { color: 'red', onlycancel: true, }, + }).onCancel(async () => { + showLoader() + await kcLogout() + setTimeout(() => { + hideLoader() + }, 1000) }) } else { const message = e.response.data.result ?? e.response.data.message @@ -169,6 +176,12 @@ export const useCounterMixin = defineStore('mixin', () => { color: 'red', onlycancel: true, }, + }).onCancel(async () => { + showLoader() + await kcLogout() + setTimeout(() => { + hideLoader() + }, 1000) }) } else { //invalid_token @@ -181,6 +194,12 @@ export const useCounterMixin = defineStore('mixin', () => { color: 'red', onlycancel: true, }, + }).onCancel(async () => { + showLoader() + await kcLogout() + setTimeout(() => { + hideLoader() + }, 1000) }) } } else if (e.response.data.successful === false) { diff --git a/src/views/MainView.vue b/src/views/MainView.vue index f50e343..7a9acce 100644 --- a/src/views/MainView.vue +++ b/src/views/MainView.vue @@ -45,20 +45,23 @@ async function fetchNotifications(index: number, type: string) { if (type === 'DEL') { notiList.value = [] } - response.map((e: Noti) => { - list.push({ - id: e.id, - sender: - e.createdFullName == '' || e.createdFullName == null - ? 'เจ้าหน้าที่'[0] - : e.createdFullName[0], - body: e.body ?? '', - timereceive: e.receiveDate, - isOpen: e.isOpen, + + if (response.length === 0) { + response.map((e: Noti) => { + list.push({ + id: e.id, + sender: + e.createdFullName == '' || e.createdFullName == null + ? 'เจ้าหน้าที่'[0] + : e.createdFullName[0], + body: e.body ?? '', + timereceive: e.receiveDate, + isOpen: e.isOpen, + }) }) - }) - notiList.value.push(...list) - statusLoad.value = totalNotiList.value === 0 ? true : false + notiList.value.push(...list) + statusLoad.value = totalNotiList.value === 0 ? true : false + } }) // .catch((err) => { // messageError($q, err)