I created a authentication system, and thus was setting jwt token in cookie. But when I refresh the page it is getting delete, even though I am setting it’s age to be of 24 hours.
jwt.sign(userData, process.env.JWT_SECRET, { expiresIn: '1h' }, (err, token) => {
if (err) {
console.log(err);
}
res.cookie('authToken', token, {
maxAge: 24 * 60 * 60 * 1000, // 24 hrs
httpOnly: true,
secure: true, // Set to true if using HTTPS
sameSite: 'None', // Adjust as needed ('Strict', 'Lax', 'None')
path: '/'
});
res.json({
success: true,
message: 'Login successful'
});
});
I tried all solutions provided by chatgpt but wasn’t able to solve it