next/composables/useApiFetch.ts

20 lines
426 B
TypeScript

import { UseFetchOptions } from "nuxt/app";
const useApiFetch = async (url: string, options?: any) => {
const at = useCookie("rockfic_cookie", { default: undefined });
const { token } = useAuth();
let head = {
...(options?.headers || {}),
};
if (token.value) {
head.Authorization = token.value;
}
return useFetch("/api" + url, {
method: "get",
headers: head,
...options,
});
};
export default useApiFetch;