mirror of
https://github.com/HangarMC/Hangar.git
synced 2024-12-21 06:51:19 +08:00
fix missing reject for ano usage
This commit is contained in:
parent
4cfa34cbe6
commit
144e940ddb
@ -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);
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user