From 144e940ddb155bfb4899093f385b844db979d765 Mon Sep 17 00:00:00 2001 From: MiniDigger | Martin Date: Wed, 15 Jun 2022 10:23:18 +0200 Subject: [PATCH] fix missing reject for ano usage --- frontend-new/src/composables/useApi.ts | 10 ++++++---- frontend-new/src/composables/useAuth.ts | 11 +++-------- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/frontend-new/src/composables/useApi.ts b/frontend-new/src/composables/useApi.ts index 2debd28fb..6b083a534 100644 --- a/frontend-new/src/composables/useApi.ts +++ b/frontend-new/src/composables/useApi.ts @@ -59,7 +59,8 @@ function request(url: string, method: AxiosRequestConfig["method"], data: obj if (retry) { // we failed on a retry, let's invalidate authLog("failed retry -> invalidate"); - return useAuth.invalidate(!import.meta.env.SSR); + await useAuth.invalidate(); + return reject(error); } // do we have a refresh token we could use? const result = await useAuth.refreshToken(); @@ -68,13 +69,14 @@ function request(url: string, method: AxiosRequestConfig["method"], data: obj authLog("Retrying request..."); try { const response = await request(url, method, data, headers, true); - resolve(response); + return resolve(response); } catch (e) { - reject(e); + return reject(e); } } else { authLog("Not retrying since refresh failed"); - return useAuth.invalidate(!import.meta.env.SSR); + await useAuth.invalidate(); + return reject(error); } } reject(error); diff --git a/frontend-new/src/composables/useAuth.ts b/frontend-new/src/composables/useAuth.ts index fde0ce192..9a1488b43 100644 --- a/frontend-new/src/composables/useAuth.ts +++ b/frontend-new/src/composables/useAuth.ts @@ -47,7 +47,7 @@ class Auth { return this.refreshPromise; } - async invalidate(shouldRedirect = true) { + async invalidate() { useAuthStore(this.usePiniaIfPresent()).$patch({ user: null, token: null, @@ -59,17 +59,12 @@ class Auth { useCookies().remove("HangarAuth", { path: "/" }); authLog("Invalidated auth cookies"); } - if (shouldRedirect) { - useContext().redirect("/logged-out"); - } } async updateUser(): Promise { const user = await useInternalApi("users/@me").catch(async (err) => { - const { trace, ...data } = err.response.data; - console.log(data); - console.log("LOGGING OUT ON updateUser"); - return this.invalidate(!import.meta.env.SSR); + authLog("no user"); + return this.invalidate(); }); if (user) { authLog("patching " + user.name);