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

91
Views
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
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!