Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

169
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda