Import
Functions
getCookie()
Retrieves cookie values from the request.The Hono context object
The name of the cookie to retrieve. If omitted, returns all cookies as an object.
Cookie prefix option:
'secure': Looks for__Secure-prefixed cookie'host': Looks for__Host-prefixed 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.The Hono context object
The name of the cookie
The value of the cookie
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.The Hono context object
The name of the cookie to delete
Cookie options (should match the options used when setting the cookie)
The value of the deleted cookie, or
undefined if it didn’t existgetSignedCookie()
Retrieves and verifies signed cookies.The Hono context object
The secret key used to sign the cookie
The name of the cookie. If omitted, returns all signed cookies.
Cookie prefix option
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.The Hono context object
The name of the cookie
The value of the cookie
The secret key used to sign the cookie
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