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

125
Views
Why cookie-session is not saving a cookie?

I am using cookie-session to check the id of an user:

const cookieSessionMiddleware = cookieSession({
    // secret: secretcookie.cookieSecret,
    secret: "dont look here, it will be a secret",
    maxAge: 100 * 60 * 60 * 24 * 14,
});

app.use(cookieSessionMiddleware);
app.post("/users", function (req, res) {
const name = req.body.name;
db.addUser(name)
    .then(({ rows }) => {
         const id = rows[0].id;
         req.session.userId = id;
        return rows[0];
    })
    .then((results) => {
        const name = results.name;
        res.json({ response: name, success: true });
        // console.log("rows-->", results);
    })
    .catch((e) => {
        res.json({ error: e, success: false });
    });
});

I am running a Create-react-app in localhost:3000 and the server.js in localhost:3001, being able to connect them with cors options.

I don't know why, but my app is not saving the cookie here. But if I do this, I can save a cookie:

app.get("/users", (req, res) => {
    req.session.userId = 5;
    console.log("from users", req.session);
    res.json({ response: req.session, success: true });
});

I checked the documentation, searched on google and looked here, but I didn't find solution. Someone knows why?

Thank you in advance!

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!