fix: automatic auth refresh
All checks were successful
ci/woodpecker/push/build-and-publish Pipeline was successful

This commit is contained in:
SauceyRed 2025-06-06 01:57:19 +02:00
parent d49d533724
commit 774e10d68c
Signed by: sauceyred
GPG key ID: 270B096EF6E9A462

View file

@ -9,8 +9,6 @@ export default async <T>(path: string, options: NitroFetchOptions<string> = {})
path = path.slice(0, path.lastIndexOf("/")); path = path.slice(0, path.lastIndexOf("/"));
} }
console.log("formatted path:", path); console.log("formatted path:", path);
const accessToken = useCookie("access_token");
console.log("access token:", accessToken.value);
const apiBase = useCookie("api_base").value; const apiBase = useCookie("api_base").value;
const apiVersion = useRuntimeConfig().public.apiVersion; const apiVersion = useRuntimeConfig().public.apiVersion;
console.log("heyoooo") console.log("heyoooo")
@ -21,10 +19,14 @@ export default async <T>(path: string, options: NitroFetchOptions<string> = {})
} }
console.log("path:", path) console.log("path:", path)
const { revoke, refresh } = useAuth(); const { revoke, refresh } = useAuth();
console.log("access token 2:", accessToken.value);
let headers: HeadersInit = {}; let headers: HeadersInit = {};
let reauthFailed = false;
while (!reauthFailed) {
const accessToken = useCookie("access_token");
console.log("access token:", accessToken.value);
if (accessToken.value) { if (accessToken.value) {
headers = { headers = {
...options.headers, ...options.headers,
@ -35,9 +37,6 @@ export default async <T>(path: string, options: NitroFetchOptions<string> = {})
...options.headers ...options.headers
}; };
} }
let reauthFailed = false;
while (!reauthFailed) {
try { try {
console.log("fetching:", URL.parse(apiBase + path)); console.log("fetching:", URL.parse(apiBase + path));
const res = await $fetch<T>(URL.parse(apiBase + path)!.href, { const res = await $fetch<T>(URL.parse(apiBase + path)!.href, {
@ -74,9 +73,10 @@ export default async <T>(path: string, options: NitroFetchOptions<string> = {})
console.log("Path is refresh endpoint, throwing error"); console.log("Path is refresh endpoint, throwing error");
throw error; throw error;
} }
} } else {
console.log("throwing error"); console.log("throwing error:", error);
throw error; throw error;
} }
} }
}
} }