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!