https://supertokens.com/ logo
#support-questions
Title
# support-questions
u

[BR1]Sky

06/20/2022, 1:32 AM
Hi friends. Everything is working as expected except GET requests from my frontend do not include the cookies to the backend. Frontend in NextJS, backend FastAPI python. I have cookieDomain set on frontend and backend, that's what made the POST requests include the cookies. The basic issue is this: When a request comes from client side I have a rewrite defined in next.config.js, like this
Copy code
javascript
const nextConfig = {
  reactStrictMode: true,
  async rewrites() {
    return [
      {
        source: '/api/:path*',
        destination: `${process.env["API_BASE_URL"]}/:path*`,
      },
    ]
  },
  env: {
    BASE_URL: process.env["BASE_URL"],
    API_BASE_URL: process.env["API_BASE_URL"]
  }
}

module.exports = nextConfig
When I make a post request from the client side like:
Copy code
javascript
export default function Home() {
...
const req = await fetch(`/api/${endpoint}`, {
          method: 'POST',
          headers: {'Content-Type': 'application/json'},
          body: JSON.stringify(body)
          });
The above rewrite, rewrites /api/ to my backend url, cookies are included and I can see that in the backend like this:
Copy code
INFO:     127.0.0.1:52558 - "POST /auth/signin HTTP/1.1" 200 OK
USER: c4a258b4-d5a8-45cc-9fcf-818af965eee3 creating short code...
INFO:     172.17.0.1:0 - "POST /create_short_code HTTP/1.1" 201 Created
However, when the request comes from the serverside in getserversideprops, like this:
Copy code
javascript
export async function getServerSideProps({ params }) {
    const req = await fetch(`${process.env.API_BASE_URL}/all_short_codes`);
    const data = await req.json();
    
    return {
        props: { urls: data }
    }
}