Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

167
Views
Cross-site request with credentials not working

I have a Nextjs app hosted on Vercel and a Nestjs API hosted on Railway (two different domains), and I am trying to make cross-site requests work. I have set up CORS and am no longer getting blocked by it. However, credentials are not being passed in the request (using axios)

Here is my axios instance used to make the call to the api

export const api = axios.create({
    baseURL: apiBaseURL,
    responseType: "json",
    withCredentials: true,
});

In the backend, I am setting the token cookie

res.setCookie(
            "token",
            this.jwtService.sign({ id: user.id, email: user.email }),
            {
                path: "/",
                secure: true,
                sameSite: "none",
                httpOnly: true,
            }
);

The token cookie is later used to authenticate the user's request and is set when the user authenticates with Google OAuth. The user chooses his account, and is redirected to the /auth/redirect API endpoint (Railway) which then sets the cookie and redirects to the front-end (Vercel)

My CORS configuration

app.enableCors({
    origin: ["http://localhost:3000", "https://my-app.vercel.app"],
    credentials: true,
});

Everytime the Front-end tries to call a protected API endpoint, the cookies are not being sent.

I am using the fastify-adapter for Nestjs.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!