fix(composables): create default/empty values for nested options fields as fallbacks

This commit is contained in:
☙◦ The Tablet ❀ GamerGirlandCo ◦❧ 2023-10-03 01:06:40 -04:00
parent 80438ecacd
commit 5dac1d6492
Signed by: tablet
GPG Key ID: 924A5F6AF051E87C

View File

@ -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,
}); });
}; };