In my NodeJS application RESTful API when user logs in I create a JWT and send it to the client in a secure, httponly cookie:
const jwt = utils.createJWT(user._id.toString());
const sessionId = utils.generateSessionId();
res.cookie(sessionId, jwt, { httpOnly: true, secure: true });
return res.status(200).json({
userId: user._id,
result: constants.SUCCESS
});
After login, subsequent API calls the browser automatically sends the secure cookie to the server.
I need to validate that the JWT has not expired, and if it has expired then I need to refresh the JWT.
But in the request to the server the cookie seems to be encrypted, so how do I extract the JWT to check if it has expired?
Ultimately what I'm trying to do is ensure that I can validate the JWT to see if it has expired, but I read that you should not store the JWT server-side, is this true, should I be trying to extract the JWT from the secure cookie and if so how?