Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

100
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda