fix(composables): create default/empty values for nested options fields as fallbacks
This commit is contained in:
parent
80438ecacd
commit
5dac1d6492
@ -3,12 +3,15 @@ import { UseFetchOptions } from "nuxt/app";
|
|||||||
const useApiFetch = async (url: string, options?: any) => {
|
const useApiFetch = async (url: string, options?: any) => {
|
||||||
const at = useCookie("rockfic_cookie", { default: undefined });
|
const at = useCookie("rockfic_cookie", { default: undefined });
|
||||||
const { token } = useAuth();
|
const { token } = useAuth();
|
||||||
|
let head = {
|
||||||
|
...(options?.headers || {}),
|
||||||
|
};
|
||||||
|
if (token.value) {
|
||||||
|
head.Authorization = token.value;
|
||||||
|
}
|
||||||
return useFetch("/api" + url, {
|
return useFetch("/api" + url, {
|
||||||
method: "get",
|
method: "get",
|
||||||
headers: {
|
headers: head,
|
||||||
...(options?.headers || {}),
|
|
||||||
Authorization: `Bearer ${token.value}`,
|
|
||||||
},
|
|
||||||
...options,
|
...options,
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user