2023-09-28 21:55:19 -04:00
|
|
|
import { UseFetchOptions } from "nuxt/app";
|
|
|
|
|
|
|
|
const useApiFetch = async (url: string, options?: any) => {
|
|
|
|
const at = useCookie("rockfic_cookie", { default: undefined });
|
|
|
|
const { token } = useAuth();
|
2023-10-03 01:06:40 -04:00
|
|
|
let head = {
|
|
|
|
...(options?.headers || {}),
|
|
|
|
};
|
|
|
|
if (token.value) {
|
|
|
|
head.Authorization = token.value;
|
|
|
|
}
|
2023-09-28 21:55:19 -04:00
|
|
|
return useFetch("/api" + url, {
|
|
|
|
method: "get",
|
2023-10-03 01:06:40 -04:00
|
|
|
headers: head,
|
2023-09-28 21:55:19 -04:00
|
|
|
...options,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
export default useApiFetch;
|