Abdennour TOUMI
Abdennour TOUMI

Reputation: 93183

read cookie age from http request in server side

req.cookies :

When using cookie-parser middleware, this property is an object that contains cookies sent by the request. If the request contains no cookies, it defaults to {}.

     // Cookie: name=tj
    req.cookies.name
    // => "tj"

This is what i found in the official documentation , However, it is expected that req.cookies.name returns an object contains all info about cookie , Not ONLY STRING which is the value of cookie .

Expected

  req.cookies.name ==> {value:"e3Lfdsd3pd1...er",expiration:...,..:...}

Actual

  req.cookies.name ==> "e3Lfdsd3pd1...er"

Upvotes: 2

Views: 934

Answers (1)

Michael Troger
Michael Troger

Reputation: 3497

You can not access this data because it's simply not there. The browser sends only the key-value pairs. expires and max-age are local informations for the browser only and will not be committed to a web server in general.

You can set those attributes on cookie creation on the server, also you can overwrite them later (e.g. for invalidating), but I'm afraid you can't read the values of those attributes.

Upvotes: 2

Related Questions