next/composables/useApiFetch.ts

17 lines
394 B
TypeScript

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