refactor(composables):
This commit is contained in:
		
							parent
							
								
									00e2457aab
								
							
						
					
					
						commit
						480dbfdde9
					
				| @ -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 <T>(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<T>(url, null, { | ||||
| 		serializer: StorageSerializers.object, | ||||
| 	}); | ||||
| 
 | ||||
| 	if (!cached.value) { | ||||
| 		const { data, error } = await useFetch<T>("/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<T>("/api" + url, { | ||||
| 		method: "get", | ||||
| 		headers: head, | ||||
| 		...options, | ||||
| 	}); | ||||
| 
 | ||||
| 	return data; | ||||
| }; | ||||
| 
 | ||||
| export default useApiFetch; | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user