Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/runtime/composables/gql-async-query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,9 @@ export async function gqlAsyncQuery<T = any>(method: string, options: IGraphQLOp

await callWithNuxt(_nuxtApp, checkTokenAndRenew);

const requestHeaders = {
const requestHeaders: Record<string, string> = {
authorization: `Bearer ${accessTokenState.value}`,
...(options.headers || {}),
};

let result = await $graphql.default.request(documentNode, variables, requestHeaders);
Expand Down
3 changes: 2 additions & 1 deletion src/runtime/composables/gql-mutation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,9 @@ export async function gqlMutation<T = any>(method: string, options: IGraphQLOpti
await callWithNuxt(_nuxtApp, checkTokenAndRenew);
}

const requestHeaders = {
const requestHeaders: Record<string, string> = {
authorization: `Bearer ${method === 'refreshToken' ? refreshTokenState.value : accessTokenState.value}`,
...(options.headers || {}),
};

let data;
Expand Down
3 changes: 2 additions & 1 deletion src/runtime/composables/gql-query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,9 @@ export async function gqlQuery<T = any>(method: string, options: IGraphQLOptions

await callWithNuxt(_nuxtApp, checkTokenAndRenew);

const requestHeaders = {
const requestHeaders: Record<string, string> = {
authorization: `Bearer ${accessTokenState.value}`,
...(options.headers || {}),
};

let data = null;
Expand Down
1 change: 1 addition & 0 deletions src/runtime/interfaces/graphql-options.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export interface IGraphQLOptions {
disableTokenCheck?: boolean;
fields?: any;
hashPasswords?: boolean;
headers?: Record<string, string>;
lazy?: boolean;
log?: boolean;
variables?: any;
Expand Down
4 changes: 4 additions & 0 deletions src/runtime/plugins/ws.client.ts
Original file line number Diff line number Diff line change
@@ -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<Record<string, string>>({});

export default defineNuxtPlugin({
name: 'ws',
Expand All @@ -13,6 +16,7 @@ export default defineNuxtPlugin({
const { accessTokenState } = useAuthState();
return {
Authorization: 'Bearer ' + accessTokenState.value,
...wsHeaders,
};
},
lazy: true,
Expand Down