Skip to main content
The Cookie Helper provides utilities for getting, setting, and managing HTTP cookies, including support for signed cookies and cookie prefixes.

Import

Functions

getCookie()

Retrieves cookie values from the request.
Context
required
The Hono context object
string
The name of the cookie to retrieve. If omitted, returns all cookies as an object.
'secure' | 'host'
Cookie prefix option:
  • 'secure': Looks for __Secure- prefixed cookie
  • 'host': Looks for __Host- prefixed cookie
string | undefined | Cookie
The cookie value, or undefined if not found. Returns all cookies as an object when key is omitted.
Example

setCookie()

Sets a cookie in the response.
Context
required
The Hono context object
string
required
The name of the cookie
string
required
The value of the cookie
CookieOptions
Cookie options:
  • domain: Cookie domain
  • expires: Expiration date
  • httpOnly: HttpOnly flag
  • maxAge: Max age in seconds
  • path: Cookie path (defaults to /)
  • secure: Secure flag
  • sameSite: SameSite attribute ('Strict', 'Lax', or 'None')
  • prefix: Cookie prefix ('secure' or 'host')
Example

deleteCookie()

Deletes a cookie by setting its max age to 0.
Context
required
The Hono context object
string
required
The name of the cookie to delete
CookieOptions
Cookie options (should match the options used when setting the cookie)
string | undefined
The value of the deleted cookie, or undefined if it didn’t exist
Example

getSignedCookie()

Retrieves and verifies signed cookies.
Context
required
The Hono context object
string | BufferSource
required
The secret key used to sign the cookie
string
The name of the cookie. If omitted, returns all signed cookies.
'secure' | 'host'
Cookie prefix option
Promise<string | undefined | false | SignedCookie>
Returns:
  • The cookie value if signature is valid
  • false if signature is invalid
  • undefined if cookie doesn’t exist
  • Object of all signed cookies when key is omitted
Example

setSignedCookie()

Sets a signed cookie in the response.
Context
required
The Hono context object
string
required
The name of the cookie
string
required
The value of the cookie
string | BufferSource
required
The secret key used to sign the cookie
CookieOptions
Cookie options (same as setCookie)
Example
Cookie prefixes are security features that enforce certain requirements:
  • __Secure-: Cookie must be set with the secure attribute
  • __Host-: Cookie must be set with secure, must have path=/, and must not have a domain attribute

Types