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

96
Visualizações
Cookies not being sent to the browser

I have a problem with my server while trying to send cookies. I am currently working on an api, when I try the code on Postman, the cookies get sent, but not on the browser. This is my current configuration.

// my current server code that sends the cookie  //

function sendCookie(user, statusCode, res) {
 const token = signToken(user._id);
 const cookieOptions = {
 expires: new Date(
  Date.now() + process.env.JWT_COOKIE_EXPIRES_IN * 24 * 60 * 60 * 1000
),
httpOnly: true,
 };
  process.env.NODE_ENV === "production" ? (cookieOptions.secure = true) : "";
  res.cookie("session", token, cookieOptions);
}

//frontend code sending the ajax request to the api

  async function login(email, password) {
     try {
       const res = await axios({
       method: "POST",
       url: "http://127.0.0.1:3000/api/v1/users/login",
       data: {
        email,
        password,
     },
     withCredentials: true,
  });

  } catch (err) {
console.log(err);
 }
}

//configuration for cors

  app.use(
   cors({
     origin: true,
     credentials: true,
  })
 );
  app.options(
   "*",
    cors({
     origin: true,
     credentials: true,
  })
   );

still with all these configurations The cookies are being sent to the browser

Thanks...

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