Switched frontend API calls to Nuxt

This commit is contained in:
lucast committed 2026-09-29 13:33:48 +02:00
1 parent 4621a81384
commit 47db7abd6a
5 files changed
+89 -69

No files matched your search

+5 -10
View File
@@ -6,14 +6,11 @@ export function useApiFetch<DataT = any, ErrorT = any>(
options?: UseFetchOptions<DataT, ErrorT>,
authorize: boolean = true,
): ReturnType<typeof useFetch<DataT, ErrorT>> {
const baseUrl = import.meta.env.VITE_PUBLIC_BACKEND
if (!baseUrl) throw new Error("BACKEND URL not set")
const { sessionToken, refreshSessionToken } = useAuth()
const defaults: UseFetchOptions<DataT, ErrorT> = {
baseURL: baseUrl,
// The migrated API lives in this Nuxt app under server/api.
baseURL: "/api",
retry: 1,
retryDelay: 0,
@@ -29,11 +26,9 @@ export function useApiFetch<DataT = any, ErrorT = any>(
if (!newToken) return
options.headers = {
...(options.headers as unknown as Record<string, string>),
// @ts-ignore
Authorization: `Bearer ${newToken}`,
}
const headers = new Headers(options.headers as HeadersInit)
headers.set("Authorization", `Bearer ${newToken}`)
options.headers = headers
}
},
}