Explorar o código

fix: :bug: loop infinito no logout

Denis hai 1 ano
pai
achega
bc69ed4b74
Modificáronse 2 ficheiros con 0 adicións e 9 borrados
  1. 0 1
      src/boot/axios.js
  2. 0 8
      src/composables/useAuth.js

+ 0 - 1
src/boot/axios.js

@@ -36,7 +36,6 @@ const errorInterceptor = async (error, app) => {
   if (error.response.status === 401) {
     const isRefreshValid = await useAuth().refreshToken();
     if (!isRefreshValid) {
-      useAuth().logout();
       app.config.globalProperties.$router.push({ name: "Login" });
     } else {
       return api.request(error.config);

+ 0 - 8
src/composables/useAuth.js

@@ -1,10 +1,8 @@
 import { api } from "src/boot/axios";
 import { Cookies } from "quasar";
 import { useRouter } from "vue-router";
-import { ref } from "vue";
 
 export const useAuth = () => {
-  const isAuthenticated = ref(false);
   const router = useRouter();
 
   const login = async (email, password) => {
@@ -30,7 +28,6 @@ export const useAuth = () => {
         Cookies.set("refresh_token", response.data.payload.refresh_token, {
           expires: refreshTokenExpiresIn,
         });
-        isAuthenticated.value = true;
       }
     } catch (error) {
       console.error(error);
@@ -40,9 +37,7 @@ export const useAuth = () => {
   const logout = async () => {
     try {
       const response = await api.post("/logout");
-
       if (response.status === 200) {
-        isAuthenticated.value = false;
         Cookies.remove("access_token");
         Cookies.remove("refresh_token");
         router.push({ name: "Login" });
@@ -74,12 +69,10 @@ export const useAuth = () => {
         Cookies.set("refresh_token", response.data.payload.refresh_token, {
           expires: refreshTokenExpiresIn,
         });
-        isAuthenticated.value = true;
       }
 
       return true;
     } catch (error) {
-      isAuthenticated.value = false;
       console.error(error);
       return false;
     }
@@ -89,6 +82,5 @@ export const useAuth = () => {
     login,
     logout,
     refreshToken,
-    isAuthenticated,
   };
 };