0

I have a nextjs application that is consuming a graphql api that is served using fastify. Here is how I'm creating a client and a Provider:

import React from "react";
import { createClient, Provider } from "urql";
export const url = "http://127.0.0.1:3001/graphql";
export const client = createClient({
  url,
  fetchOptions: () => {
    const token = undefined;
    return {
      headers: { authorization: token ? `Bearer ${token}` : "" },
      credentials: "include",
    };
  },
});

type Props = {
  children: React.ReactNode;
};
const UrqlProvider: React.FunctionComponent<Props> = ({ children }) => {
  return <Provider value={client}>{children}</Provider>;
};

export default UrqlProvider;

As far as i know setting the credentials: "include" in the fetch options from Apollo set's the cookies in the browser but surprisingly I'm not getting the same with urql but i can see in the Network tab of my browser the following in the Response headers

access-control-allow-credentials: true
access-control-allow-origin: http://localhost:3000
Connection: keep-alive
content-length: 29
content-type: application/json; charset=utf-8
Date: Wed, 22 Feb 2023 15:40:46 GMT
Keep-Alive: timeout=72
set-cookie: name=Me; Max-Age=604800000; Path=/; SameSite=None
vary: Origin

What may be possibly the problem because if i test it using Postman it is working.

crispengari
  • 7,901
  • 7
  • 45
  • 53

0 Answers0