I create an online store for a diploma project, I log in with a username and password, write the user's name and surname in the cookie, they are read, and then become unavailable. I thought the problem was the cookie lifetime, but after I set the maxAge value: 1000*60*60 and httpOnly:false nothing has changed. When I write cookies through the get method, all cookies remain, and when I write them through the post method, they are not saved Here is the code for creating and sending cookies:
app.post("/signIn", urlencodedParser, function (request, response) {
if(!request.body) return response.sendStatus(400);
connection.query(`SELECT user_name,
user_surname
FROM users where (${(request.body.login.match(/^\d+$/) !== null) ?
`telephone=${request.body.login}` :
`email='${request.body.login}'`}) and
password='${request.body.password}'`,
(err, users) => {
if(err == null && (typeof users[0] === "object"&& users[0] !== undefined)) {
response.cookie('userName', users[0].user_name);
response.cookie('userSurname', users[0].user_surname);
response.cookie('successAuthentication', 'true');
response.sendFile(`${__dirname}/public/html/index.html`);
} else if(err == null && users[0] === undefined) {
connection.query(`SELECT worker_name,
worker_surname,
position_name
FROM worker inner join position on
worker_id = position_id where (${(request.body.login.match(/^\d+$/) !== null) ?
`telephone=${request.body.login}` :
`email='${request.body.login}'`}) and
password='${request.body.password}'`, (workerSelectErr, worker) => {
if(workerSelectErr == null && worker !== []) {
response.cookie('workerName', worker[0].worker_name);
response.cookie('workerSurname', worker[0].worker_surname);
response.cookie('successAuthentication', 'true');
response.sendFile(`${__dirname}/public/html/indexWorker.html`);
}
});
} else if(err != null) {
throw new Error(err);
}
});
});