node.js – Unable to update cookie from server Express js Node GraphQL
I need to be able to update a given cookie on the server inside my express and apollo graphql application. I’ve tried this and it’s not able to update the cookie (res is type Response from express npm package)
res.cookie(COOKIE_KEY, refreshToken, {
path: "https://stackoverflow.com/",
httpOnly: false,
});
I’m using apollo graphql on the client side, here is my setup for that:
const authLink = setContext(async (_, { headers }) => {
return {
headers: {
...headers,
...getAuthHeaders(),
},
};
});
let apolloClient: ApolloClient<NormalizedCacheObject> | undefined;
export function createApolloClient(headers?: Record<string, unknown>) {
const link = ApolloLink.from([
authLink,
createUploadLink({
uri:
process.env.NODE_ENV === 'production'
? `${process.env.NEXT_PUBLIC_API_URL}/graphql`
: 'http://localhost:8000/graphql',
credentials: 'include',
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore - this has the wrong type
headers,
}),
]);
const client = new ApolloClient({
uri:
process.env.NODE_ENV === 'production'
? `${process.env.NEXT_PUBLIC_API_URL}/graphql`
: 'http://localhost:8000/graphql',
cache: new InMemoryCache(),
ssrMode: isServer(),
connectToDevTools: !isServer(),
link,
});
return client;
}
Read more here: Source link
