diff --git a/app/composables/useApiFetch.ts b/app/composables/useApiFetch.ts index ffc0241..a19f902 100644 --- a/app/composables/useApiFetch.ts +++ b/app/composables/useApiFetch.ts @@ -4,7 +4,7 @@ import defu from "defu" export function useApiFetch( url: string | Request | Ref | (() => string | Request), options?: UseFetchOptions, - authorize: boolean = true + authorize: boolean = true, ): ReturnType> { const baseUrl = import.meta.env.VITE_PUBLIC_BACKEND @@ -15,26 +15,25 @@ export function useApiFetch( const defaults: UseFetchOptions = { baseURL: baseUrl, + retry: 1, + retryDelay: 0, + retryStatusCodes: [401], + headers: authorize && sessionToken.value ? { Authorization: `Bearer ${sessionToken.value}` } : {}, - onResponseError: async ({ response, options }) => { + onResponseError: async ({ request, response, options }) => { if (response.status == 401 && authorize) { const newToken = await refreshSessionToken() if (!newToken) return - const newOptions = { - ...options, - headers: { - ...(options.headers || {}), - Authorization: `Bearer ${newToken}`, - }, + options.headers = { + ...(options.headers as unknown as Record), + // @ts-ignore + Authorization: `Bearer ${newToken}`, } - - // @ts-ignore - return await $fetch(url, newOptions) } }, } diff --git a/app/pages/album/[id].vue b/app/pages/album/[id].vue index e50cd4f..8bd2346 100644 --- a/app/pages/album/[id].vue +++ b/app/pages/album/[id].vue @@ -12,7 +12,7 @@ const { playAlbum, playShuffledAlbum, playAlbumAtIndex } = usePlayer()