Nat
Nat

Reputation: 749

Remove cookie when browser close in NodeJS

How do I remove or delete cookies when users close the browser? I have the code here using cookie-parser in NodeJS with the maxAge property which I do not know what value should I put in order to delete the cookie when users close the browser. I believe Many thanks in advance and greatly appreciated.

res.cookie('authcookie',accessToken,{maxAge:???,httpOnly:true})

Upvotes: 0

Views: 1429

Answers (1)

jfriend00
jfriend00

Reputation: 707786

If there is no Expires or Max-Age parameter set for the cookie, then the browser will treat is as a "session cookie" and will not store the cookie beyond the current browsing session (typically kept only in memory). So, when the browser is closed, the cookie will be gone.

Upvotes: 3

Related Questions