import { AsyncData } from "#app"; const useApiFetch = async (url: string, options?: any) => { const { token } = useAuth(); let head = { ...(options?.headers || {}), }; if (token.value) { head.Authorization = token.value; } /* 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}`); // } console.log(`API => /api${url}`); return (await useFetch(`/api${url}`, { // @ts-ignore method: "get", headers: head, ...options, })) as AsyncData; }; export default useApiFetch;