Guides  ›  Request  ›  Cookies ← PREV NEXT →

Cookies

Read, set, and delete cookies through state.req.cookie().

function handler(state) {
  var theme = state.req.cookie('theme') // string or null

  state.req.cookie('theme', 'dark', {
    days: 30,
    path: '/',
    sameSite: 'Lax',
    httpOnly: true,
    secure: true
  })

  state.req.cookie('old-theme', null) // delete
  return { theme }
}

Writes are sent with the response. secure: true is for HTTPS. Defaults: 30 days, /, Lax, and both flags false. In this version, days: 0 also uses 30 days.

Next: HTML →

Tools for business systems.