From a966b46ca369c3bf2e7b06c2a32022cc9f010bc2 Mon Sep 17 00:00:00 2001 From: Pascal Klesse Date: Thu, 13 Jun 2024 10:05:15 +0200 Subject: [PATCH] fix: fix apollo headers --- src/runtime/plugins/apollo.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/runtime/plugins/apollo.ts b/src/runtime/plugins/apollo.ts index d1efe41..aac360c 100644 --- a/src/runtime/plugins/apollo.ts +++ b/src/runtime/plugins/apollo.ts @@ -76,6 +76,7 @@ export default defineNuxtPlugin({ const authLink = setContext((_, { headers }) => { const { accessTokenState, refreshTokenState } = useAuthState(); let token: string; + let cookies: string = headers?.cookies ?? defaultHeaders?.cookies ?? ''; console.log(defaultHeaders, headers); @@ -87,12 +88,17 @@ export default defineNuxtPlugin({ } } + if (process.client) { + cookies = (cookies.length ? cookies + '; ' : '') + document.cookie; + } + return { headers: { ...headers, ...defaultHeaders, Authorization: token ? `Bearer ${token}` : '', // Token in header - origin: defaultHeaders?.origin ?? defaultHeaders?.referer, + cookies: cookies, + origin: headers.origin ?? defaultHeaders?.origin ?? defaultHeaders?.referer, }, }; });