fixing check token
This commit is contained in:
parent
8d51e6f623
commit
f6b2b26998
5 changed files with 33 additions and 21 deletions
|
|
@ -1,5 +1,5 @@
|
|||
import Axios, { type AxiosRequestConfig, type AxiosResponse } from "axios";
|
||||
import keycloak from "./keycloak";
|
||||
import keycloak, { kcLogout } 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) {
|
||||
window.location.href = "/login";
|
||||
kcLogout();
|
||||
|
||||
// Store.commit("SET_ERROR_MESSAGE", error.response.data.message);
|
||||
// Store.commit("REMOVE_ACCESS_TOKEN")
|
||||
|
|
|
|||
|
|
@ -9,5 +9,17 @@ const keycloakConfig = {
|
|||
};
|
||||
|
||||
const keycloak = new Keycloak(keycloakConfig);
|
||||
|
||||
async function kcLogout() {
|
||||
await deleteCookie("BMAHRIS_KEYCLOAK_IDENTITY");
|
||||
await deleteCookie("BMAHRIS_KEYCLOAK_REFRESH");
|
||||
keycloak.logout();
|
||||
window.location.href = "/login";
|
||||
}
|
||||
|
||||
function deleteCookie(name: string) {
|
||||
document.cookie = `${name}=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;`;
|
||||
}
|
||||
|
||||
export default keycloak;
|
||||
export { keycloakConfig };
|
||||
export { keycloakConfig, kcLogout };
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue