From 480dbfdde9b3753285501f8083b371262aea0d39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=98=99=E2=97=A6=20The=20Tablet=20=E2=9D=80=20GamerGirla?= =?UTF-8?q?ndCo=20=E2=97=A6=E2=9D=A7?= Date: Thu, 5 Oct 2023 02:10:53 -0400 Subject: [PATCH] refactor(composables): --- composables/useApiFetch.ts | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/composables/useApiFetch.ts b/composables/useApiFetch.ts index fdba2b1..b94dfab 100644 --- a/composables/useApiFetch.ts +++ b/composables/useApiFetch.ts @@ -1,7 +1,7 @@ +import { StorageSerializers } from "@vueuse/core"; import { UseFetchOptions } from "nuxt/app"; -const useApiFetch = async (url: string, options?: any) => { - const at = useCookie("rockfic_cookie", { default: undefined }); +const useApiFetch = async (url: string, options?: any) => { const { token } = useAuth(); let head = { ...(options?.headers || {}), @@ -9,11 +9,36 @@ const useApiFetch = async (url: string, options?: any) => { if (token.value) { head.Authorization = token.value; } - return useFetch("/api" + url, { + /* const cached = useSessionStorage(url, null, { + serializer: StorageSerializers.object, + }); + + if (!cached.value) { + const { data, error } = await useFetch("/api" + url, { + method: "get", + headers: head, + ...options, + }); + + if (error.value) { + throw createError({ + ...error.value, + statusMessage: `Could not fetch data from ${url}`, + }); + } */ + + // Update the cache + // cached.value = data.value as T; + // } else { + // console.log(`Getting value from cache for ${url}`); + // } + const data = await useFetch("/api" + url, { method: "get", headers: head, ...options, }); + + return data; }; export default useApiFetch;