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

120
Views
sending data from client to server for cookie store empty object

I have a server api code that sets the cookies, defining the user data via req.body isn't setting the cookie with empty object. But works fine when sending a predefined data in server code.

Server code:

router.get("/addCartToCookie", function(req, res){
  let options = {
    maxAge: 1000 * 60 * 15,
    httpOnly: true, 
    path: "/",
    sameSite: "strict",
  };

  let cartData = {
    name: req.body.name,
    slug: req.body.slug,
    productPictures: req.body.productPictures,
    price: req.body.price,
    description: req.body.description,
    quantity: req.body.quantity,
  };

  // Set cookie
  res.cookie("cartName", cartData, options); // options is optional
  res.send("Cart Added to Cookie");
});

Client Code:

  const addToCartCookie = () => {
    console.log("Calling add to cart cookie");
    axios
      .get(
        "http://localhost:4001/api/addCartToCookie",
        {
          name: product.name,
          slug: product.slug,
          productPictures: product.productPictures[0].img,
          description: "sabdsjbfjsd",
          price: product.storePrice,
          quantity: itemCount,
        },
        { withCredentials: true }
      )
      .then((response) => {
        console.log(response.data);
      })
      .catch(function (error) {
        console.log(error);
      });
  };
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!