File tree Expand file tree Collapse file tree 1 file changed +10
-1
lines changed
Expand file tree Collapse file tree 1 file changed +10
-1
lines changed Original file line number Diff line number Diff line change @@ -2,22 +2,31 @@ import React from 'react';
22import { type TypedDocumentNode } from '@graphql-typed-document-node/core' ;
33import { QueryClient } from '@tanstack/react-query' ;
44import { request } from 'graphql-request' ;
5+ import { getSession } from 'next-auth/react' ;
56
67import { gqlConfig } from '@/config/site' ;
78
89// create a wrapper function for graphql-request
910// that will be used by react-query
11+
1012export async function GraphQL < TResult , TVariables > (
1113 document : TypedDocumentNode < TResult , TVariables > ,
1214 ...[ variables ] : TVariables extends Record < string , never > ? [ ] : [ TVariables ]
1315) {
16+ const session = await getSession ( ) ;
17+
18+ const headers = {
19+ ...gqlConfig . headers ,
20+ ...( session ? { Authorization : session ?. access_token } : { } ) ,
21+ } ;
22+
1423 const data = await request (
1524 `${ process . env . NEXT_PUBLIC_BACKEND_GRAPHQL_URL } ` ,
1625 document ,
1726 {
1827 ...variables ,
1928 } ,
20- { ... gqlConfig . headers }
29+ headers
2130 ) ;
2231 return data ;
2332}
You can’t perform that action at this time.
0 commit comments