Skip to content

Commit

Permalink
fix: fix apollo headers
Browse files Browse the repository at this point in the history
  • Loading branch information
Pascal Klesse committed Jun 13, 2024
1 parent d7e8170 commit a966b46
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/runtime/plugins/apollo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

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

0 comments on commit a966b46

Please sign in to comment.