From f4db48d0bfe616e96ee52143b4f1c7746c74cd7f Mon Sep 17 00:00:00 2001 From: waruneeauy Date: Fri, 16 Aug 2024 14:11:55 +0700 Subject: [PATCH] fixing check token auth --- src/plugins/http.ts | 4 ++-- src/stores/mixin.ts | 22 +++++++++++++++++++--- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/plugins/http.ts b/src/plugins/http.ts index 1e65294ee..292f1347b 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 @@ -33,7 +33,7 @@ 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(); + // 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 955228d06..a2740ceff 100644 --- a/src/stores/mixin.ts +++ b/src/stores/mixin.ts @@ -3,6 +3,7 @@ import "moment/dist/locale/th"; import moment from "moment"; import CustomComponent from "@/components/CustomDialog.vue"; import { Loading, QSpinnerCube } from "quasar"; +import { kcLogout } from "@/plugins/keycloak"; moment.locale("th"); @@ -346,7 +347,6 @@ export const useCounterMixin = defineStore("mixin", () => { } const messageError = (q: any, e: any = "", msg: string = "") => { - // q.dialog.hide(); if (e.response !== undefined) { if (e.response.data.status !== undefined) { if (e.response.data.status == 401) { @@ -360,6 +360,12 @@ export const useCounterMixin = defineStore("mixin", () => { color: "red", onlycancel: true, }, + }).onCancel(async () => { + showLoader(); + await kcLogout(); + setTimeout(() => { + hideLoader(); + }, 1000); }); } else if (e.response.data.status == 400 && e.response.data.title) { //validation errors @@ -398,6 +404,12 @@ export const useCounterMixin = defineStore("mixin", () => { color: "red", onlycancel: true, }, + }).onCancel(async () => { + showLoader(); + await kcLogout(); + setTimeout(() => { + hideLoader(); + }, 1000); }); } else { //invalid_token @@ -410,6 +422,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) { @@ -437,8 +455,6 @@ export const useCounterMixin = defineStore("mixin", () => { } } } else { - console.error("err===>", e); // *** - if (e.message && e.message !== "R is not a function") { q.dialog({ component: CustomComponent,