Next.js Discord

Discord Forum

Nextjs send cookies cross domain

Unanswered
Spectacled bear posted this in #help-forum
Open in Discord
Spectacled bearOP
hi there, my client is running on different port and my server is running on different port, I'm using
    credentials: "include",
in my requests, but upon checking these cookies are not getting sent back to backend for some reason. I've tried adding headers in nextjs config file also, it's not working either. Could anyone help?

Code for next config
/** @type {import('next').NextConfig} */
const nextConfig = {
  async headers() {
    return [
      {
        source: `https://server-url.com/:path*`,
        headers: [
          { key: "Access-Control-Allow-Credentials", value: "true" },
          { key: "Access-Control-Allow-Origin", value: "*" },
          {
            key: "Access-Control-Allow-Methods",
            value: "GET,OPTIONS,PATCH,DELETE,POST,PUT",
          },
          {
            key: "Access-Control-Allow-Headers",
            value:
              "X-CSRF-Token, X-Requested-With, Accept, Accept-Version, Content-Length, Content-MD5, Content-Type, Date, X-Api-Version",
          },
        ],
      },
    ];
  },
  eslint: {
    ignoreDuringBuilds: true,
  }
};

module.exports = nextConfig;

1 Reply

Spectacled bearOP
Anyone?