I've got a NextJS app where I am implementing Supabase for authentication, and attempting to strip out Apollo with Urql instead.
In my urql.ts
file, I am creating the client as such:
import { createClient, ssrExchange, dedupExchange, fetchExchange } from 'urql';
import { cacheExchange } from '@urql/exchange-graphcache';
import { devtoolsExchange } from '@urql/devtools';
const isServerSide = typeof window === 'undefined';
const ssrCache = ssrExchange({
isClient: !isServerSide,
initialState: !isServerSide ? window.__URQL_DATA__ : undefined,
});
const client = createClient({
url: '/api/graphql',
exchanges: [
devtoolsExchange,
dedupExchange,
cacheExchange({}),
ssrCache,
fetchExchange,
],
fetchOptions: () => {
return {
credentials: 'include',
headers: { Authorization: `Bearer ${token}` }, // how to return token?
};
},
});
export { client, ssrCache };
I am trying to figure out how to actually return the token? Because context isn't passed, I am unable to pull it from there. Supabase sets the token as HttpOnly, so I believe that is also preventing me from accessing it here. Using a library such as Js-Cookie returns undefined.
Is there a way to pass context to fetchOptions
, or should I try and figure out how to remove HttpOnly when the cookie is being set?