Original code:
const token = jwt.sign({ _id: user._id }, process.env.JWT_SECRET, { expiresIn: '1d' });
res.cookie('token', token, { expiresIn: '1d' });
This worked. The token expired in exactly one day from its creation.
The change:
const token = jwt.sign({ _id: user._id }, process.env.JWT_SECRET, { expiresIn: '1m' });
res.cookie('token', token, { expiresIn: '1m' });
I signed out, restarted the server, but still no change! The token still set itself to expire in one day. I'm following a course and when the course instructor made this change in his code, it worked as expected. The token expired in one minute.
I even tried:
const token = jwt.sign({ _id: user._id }, process.env.JWT_SECRET, { expiresIn: '10' });
res.cookie('token', token, { expiresIn: '10' });
Expecting the token to expire in ten seconds or ten milliseconds (I'm not sure what the default unit is) but still the same result. The token still is set to expire in one day.
Is this a cache thing? I have almost zero knowledge on cache, what it is, and how it works, but it is hard for me to imagine that the explanation to this is within the regular bounds of NodeJS coding itself. It would be pretty straightforward if it was. There is no other "configuration" of the jwt module or of how my app handles cookies or tokens in the entire app.
I included the next.js tag because I am using this in a next.js application (although I'm doubtful that is relevant, I could be wrong of course).