fixing check token auth

This commit is contained in:
Warunee Tamkoo 2024-08-16 14:11:55 +07:00
parent e1acb72512
commit f4db48d0bf
2 changed files with 21 additions and 5 deletions

View file

@ -1,5 +1,5 @@
import Axios, { type AxiosRequestConfig, type AxiosResponse } from "axios"; import Axios, { type AxiosRequestConfig, type AxiosResponse } from "axios";
import keycloak, { kcLogout } from "./keycloak"; import keycloak from "./keycloak";
const http = Axios.create({ const http = Axios.create({
timeout: 1000000000, // เพิ่มค่า timeout timeout: 1000000000, // เพิ่มค่า timeout
@ -33,7 +33,7 @@ http.interceptors.response.use(
// eslint-disable-next-line no-prototype-builtins // eslint-disable-next-line no-prototype-builtins
if (error.hasOwnProperty("response")) { if (error.hasOwnProperty("response")) {
if (error.response.status === 401 || error.response.status === 403) { if (error.response.status === 401 || error.response.status === 403) {
kcLogout(); // kcLogout();
// Store.commit("SET_ERROR_MESSAGE", error.response.data.message); // Store.commit("SET_ERROR_MESSAGE", error.response.data.message);
// Store.commit("REMOVE_ACCESS_TOKEN") // Store.commit("REMOVE_ACCESS_TOKEN")
} }

View file

@ -3,6 +3,7 @@ import "moment/dist/locale/th";
import moment from "moment"; import moment from "moment";
import CustomComponent from "@/components/CustomDialog.vue"; import CustomComponent from "@/components/CustomDialog.vue";
import { Loading, QSpinnerCube } from "quasar"; import { Loading, QSpinnerCube } from "quasar";
import { kcLogout } from "@/plugins/keycloak";
moment.locale("th"); moment.locale("th");
@ -346,7 +347,6 @@ export const useCounterMixin = defineStore("mixin", () => {
} }
const messageError = (q: any, e: any = "", msg: string = "") => { const messageError = (q: any, e: any = "", msg: string = "") => {
// q.dialog.hide();
if (e.response !== undefined) { if (e.response !== undefined) {
if (e.response.data.status !== undefined) { if (e.response.data.status !== undefined) {
if (e.response.data.status == 401) { if (e.response.data.status == 401) {
@ -360,6 +360,12 @@ export const useCounterMixin = defineStore("mixin", () => {
color: "red", color: "red",
onlycancel: true, onlycancel: true,
}, },
}).onCancel(async () => {
showLoader();
await kcLogout();
setTimeout(() => {
hideLoader();
}, 1000);
}); });
} else if (e.response.data.status == 400 && e.response.data.title) { } else if (e.response.data.status == 400 && e.response.data.title) {
//validation errors //validation errors
@ -398,6 +404,12 @@ export const useCounterMixin = defineStore("mixin", () => {
color: "red", color: "red",
onlycancel: true, onlycancel: true,
}, },
}).onCancel(async () => {
showLoader();
await kcLogout();
setTimeout(() => {
hideLoader();
}, 1000);
}); });
} else { } else {
//invalid_token //invalid_token
@ -410,6 +422,12 @@ export const useCounterMixin = defineStore("mixin", () => {
color: "red", color: "red",
onlycancel: true, onlycancel: true,
}, },
}).onCancel(async () => {
showLoader();
await kcLogout();
setTimeout(() => {
hideLoader();
}, 1000);
}); });
} }
} else if (e.response.data.successful === false) { } else if (e.response.data.successful === false) {
@ -437,8 +455,6 @@ export const useCounterMixin = defineStore("mixin", () => {
} }
} }
} else { } else {
console.error("err===>", e); // ***
if (e.message && e.message !== "R is not a function") { if (e.message && e.message !== "R is not a function") {
q.dialog({ q.dialog({
component: CustomComponent, component: CustomComponent,