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.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 domainexpires: Expiration datehttpOnly: HttpOnly flagmaxAge: Max age in secondspath: Cookie path (defaults to/)secure: Secure flagsameSite: SameSite attribute ('Strict','Lax', or'None')prefix: Cookie prefix ('secure'or'host')
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 existgetSignedCookie()
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
falseif signature is invalidundefinedif cookie doesn’t exist- Object of all signed cookies when key is omitted
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)Cookie Prefixes
Cookie prefixes are security features that enforce certain requirements:__Secure-: Cookie must be set with thesecureattribute__Host-: Cookie must be set withsecure, must havepath=/, and must not have adomainattribute