Reputation: 179
I have a server in expressjs that sets a cookie as follows:
res.cookie("key","value", { expires: new Date(Date.now() + 432000000), maxAge: 432000000, secure: false, sameSite: true})
The client now sends this cookie in every request. I am able to view it by doing this:
console.log(req.headers.cookie)
Output
key=value
I want to get the cookie's other details like 'expires', 'maxAge' from the request, so that I can check if it has expired. Can anyone please help me to achieve this in Expressjs
Upvotes: 0
Views: 256
Reputation: 708116
If the cookie has expired as of the time of the http request, it will not be sent to the server as the browser will remove it from its storage and no longer send it.
Expiration data is not sent back to the server by the client - only the name and value are sent back to the server. The expiration data is housekeeping info for the client and it is used there and kept there.
If you want the server to know some sort of future time value that was previously set for this client, then you will have to manually set a value as a cookie and keep track of it yourself that way or use some server-side session data that is associated with a session key cookie.
Upvotes: 1