netlify-functions-workshop icon indicating copy to clipboard operation
netlify-functions-workshop copied to clipboard

maxAge should be in seconds

Open zmb3 opened this issue 4 years ago • 0 comments

A cookie's Max-Age is the number of seconds until expiration, so the following code doesn't do what the author intended.

  const hour = 3600000
  const twoWeeks = 14 * 24 * hour
  const myCookie = cookie.serialize('my_cookie', 'lolHi', {
    secure: true,
    httpOnly: true,
    path: '/',
    maxAge: twoWeeks,
  })

An hour is 60*60=3600 seconds, it looks like this code is treating the max age as milliseconds.

zmb3 avatar Jan 26 '21 17:01 zmb3