Error: Invariant: cookies() expects to have requestAsyncStorage, none available.

2024.01.19

import { cookies } from 'next/headers';
import { GraphQLClient } from 'graphql-request';
import { API_BASE_URL } from '@/utils/config';

const serverGraphqlClient = async () => {
return new GraphQLClient(`${API_BASE_URL}/api/graphql`, {
headers: {
authorization: `Bearer ${cookies()?.get('token')?.value}`,
},
});
};

export { serverGraphqlClient as serverGraphql };
  • should use cookies inside async function.

--

--