fix missing reject for ano usage

This commit is contained in:
MiniDigger | Martin 2022-06-15 10:23:18 +02:00
parent 4cfa34cbe6
commit 144e940ddb
2 changed files with 9 additions and 12 deletions

View File

@ -59,7 +59,8 @@ function request<T>(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<T>(url: string, method: AxiosRequestConfig["method"], data: obj
authLog("Retrying request...");
try {
const response = await request<T>(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);

View File

@ -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<void> {
const user = await useInternalApi<HangarUser>("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);