I normally see auth headers added to apollo client like this (this is pasted from Apollo’s Docs and then edited to match your example). This is how I am using my Apollo Client. Then inside the authLink I am also checking for cookies and if I find one use that to authenticate instead of the public key I made in Fauna.
import { ApolloClient, createHttpLink, InMemoryCache } from '@apollo/client';
import { setContext } from '@apollo/client/link/context';
const httpLink = createHttpLink({
uri: 'https://graphql.fauna.com/graphql',
});
const authLink = setContext((_, { headers }) => {
return {
headers: {
...headers,
authorization: `Bearer ${process.env.FAUNA_ADMIN_KEY}`
}
}
});
const client = new ApolloClient({
ssrMode: typeof window === 'undefined',
link: authLink.concat(httpLink),
cache: new InMemoryCache()
});
I have never tried adding auth headers to Apollo Client like you’re doing it in your example so I am not sure if this is going to fix your issue or not. I am also using Nextjs and I was able to get my Apollo Client running this way. One other thing you might want to check is that the key you’re using to authenticate has been given the permissions needed in Fauna’s dashboard to access the query you’re trying to run.
Hope this helps!