NextAuth on Apollo Client SSR

Sorry for the bit of a irrelevant question for the discord but is it possible to configure authLink with nextauth on apollo client ssr? My apollo client is basically this repo https://github.com/kellenmace/apollo-client-cache-rehydration-in-next-js/blob/main/lib/apolloClient.ts Plus with this auth link
const authLink = () => {
return setContext(async (_, { headers }) => {
const session = await getSession();

return {
headers: {
...headers,
authorization: `Bearer ${session?.token}`,
},
};
});
};
const authLink = () => {
return setContext(async (_, { headers }) => {
const session = await getSession();

return {
headers: {
...headers,
authorization: `Bearer ${session?.token}`,
},
};
});
};
Which is used in
function createApolloClient() {
return new ApolloClient({
ssrMode: typeof window === "undefined",
link: authLink().concat(
new HttpLink({
uri: process.env.NEXT_PUBLIC_API_URL,
}),
),
cache: new InMemoryCache({
typePolicies: {
Query: {
fields: {
posts: relayStylePagination(),
},
},
},
}),
});
}
function createApolloClient() {
return new ApolloClient({
ssrMode: typeof window === "undefined",
link: authLink().concat(
new HttpLink({
uri: process.env.NEXT_PUBLIC_API_URL,
}),
),
cache: new InMemoryCache({
typePolicies: {
Query: {
fields: {
posts: relayStylePagination(),
},
},
},
}),
});
}
Been on this issue for that last two days and im starting to feel like its not possible, PLEASE PROVE ME WRONG im about to go insane
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server