From 5dac1d64927f4fd83f2505371a5e6d778b431067 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=98=99=E2=97=A6=20The=20Tablet=20=E2=9D=80=20GamerGirla?= =?UTF-8?q?ndCo=20=E2=97=A6=E2=9D=A7?= Date: Tue, 3 Oct 2023 01:06:40 -0400 Subject: [PATCH] fix(composables): create default/empty values for nested options fields as fallbacks --- composables/useApiFetch.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/composables/useApiFetch.ts b/composables/useApiFetch.ts index cad1806..fdba2b1 100644 --- a/composables/useApiFetch.ts +++ b/composables/useApiFetch.ts @@ -3,12 +3,15 @@ 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: { - ...(options?.headers || {}), - Authorization: `Bearer ${token.value}`, - }, + headers: head, ...options, }); };