diff --git a/src/runtime/composables/gql-async-query.ts b/src/runtime/composables/gql-async-query.ts index 03d4cad..8583fdf 100644 --- a/src/runtime/composables/gql-async-query.ts +++ b/src/runtime/composables/gql-async-query.ts @@ -122,8 +122,9 @@ export async function gqlAsyncQuery(method: string, options: IGraphQLOp await callWithNuxt(_nuxtApp, checkTokenAndRenew); - const requestHeaders = { + const requestHeaders: Record = { authorization: `Bearer ${accessTokenState.value}`, + ...(options.headers || {}), }; let result = await $graphql.default.request(documentNode, variables, requestHeaders); diff --git a/src/runtime/composables/gql-mutation.ts b/src/runtime/composables/gql-mutation.ts index 88ee391..c14a2b8 100644 --- a/src/runtime/composables/gql-mutation.ts +++ b/src/runtime/composables/gql-mutation.ts @@ -132,8 +132,9 @@ export async function gqlMutation(method: string, options: IGraphQLOpti await callWithNuxt(_nuxtApp, checkTokenAndRenew); } - const requestHeaders = { + const requestHeaders: Record = { authorization: `Bearer ${method === 'refreshToken' ? refreshTokenState.value : accessTokenState.value}`, + ...(options.headers || {}), }; let data; diff --git a/src/runtime/composables/gql-query.ts b/src/runtime/composables/gql-query.ts index dc2f3ad..36de856 100644 --- a/src/runtime/composables/gql-query.ts +++ b/src/runtime/composables/gql-query.ts @@ -121,8 +121,9 @@ export async function gqlQuery(method: string, options: IGraphQLOptions await callWithNuxt(_nuxtApp, checkTokenAndRenew); - const requestHeaders = { + const requestHeaders: Record = { authorization: `Bearer ${accessTokenState.value}`, + ...(options.headers || {}), }; let data = null; diff --git a/src/runtime/interfaces/graphql-options.interface.ts b/src/runtime/interfaces/graphql-options.interface.ts index 7098ba1..3d918c8 100644 --- a/src/runtime/interfaces/graphql-options.interface.ts +++ b/src/runtime/interfaces/graphql-options.interface.ts @@ -9,6 +9,7 @@ export interface IGraphQLOptions { disableTokenCheck?: boolean; fields?: any; hashPasswords?: boolean; + headers?: Record; lazy?: boolean; log?: boolean; variables?: any; diff --git a/src/runtime/plugins/ws.client.ts b/src/runtime/plugins/ws.client.ts index 41cc218..0692501 100644 --- a/src/runtime/plugins/ws.client.ts +++ b/src/runtime/plugins/ws.client.ts @@ -1,6 +1,9 @@ import { useAuth, useAuthState } from '#imports'; import { createClient } from 'graphql-ws'; import { defineNuxtPlugin, useNuxtApp, useRuntimeConfig } from 'nuxt/app'; +import { reactive } from 'vue'; + +export const wsHeaders = reactive>({}); export default defineNuxtPlugin({ name: 'ws', @@ -13,6 +16,7 @@ export default defineNuxtPlugin({ const { accessTokenState } = useAuthState(); return { Authorization: 'Bearer ' + accessTokenState.value, + ...wsHeaders, }; }, lazy: true,