Elysia treats cookies as reactive signal-like objects. Instead of separate get and set functions, you destructure the cookie name from context and read or write itsDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/elysiajs/documentation/llms.txt
Use this file to discover all available pages before exploring further.
.value directly. Changes are reflected in the response headers automatically.
Cookie objects can never be
undefined because they are Proxy instances. Only cookie.value can be undefined. Use a cookie schema or disable strictNullChecks in tsconfig.json to suppress TypeScript warnings.Reactivity
The cookie jar is a single source of truth. When you assign tocookie.value or update an attribute, Elysia automatically syncs the Set-Cookie response header. Iterating over the cookie object only yields cookies that were actually sent in the request.
Cookie attributes
Set individual attributes directly on the cookie object, or useset / add for batch updates.
Direct assignment
set
Reset all attributes and apply the new values at once:add
Merge new values into the existing attributes without resetting unrelated ones:Removing cookies
Use.remove() on the cookie or the delete operator on the cookie jar:
Cookie schema
Validate cookie values and get full TypeScript inference by passing at.Cookie schema to the route handler.
Nullable cookies
Wrap the cookie type witht.Optional to allow a cookie to be absent:
Cookie signatures
Signing a cookie appends a cryptographic hash derived from the cookie value and a secret key. Elysia verifies the signature on every request and rejects tampered cookies.Per-route signing
Providesecrets and a sign array listing the cookie names to protect:
Global signing via constructor
Apply signing globally to all routes by configuring the Elysia instance:Cookie rotation
To rotate secrets without invalidating existing cookies, pass an array of secrets. Elysia signs new cookies with the first secret and verifies against all secrets in the array.Transitioning from unsigned to signed cookies
Includenull at the end of the secrets array to allow existing unsigned cookies to pass through during the migration period:
Attribute reference
| Attribute | Default | Description |
|---|---|---|
domain | — | Restricts cookie to a specific domain |
encode | encodeURIComponent | Function used to encode the cookie value |
expires | — | Absolute expiry date (use maxAge when both are needed) |
httpOnly | false | Prevents client-side JavaScript from reading the cookie |
maxAge | — | Relative expiry in seconds; takes precedence over expires |
path | handler path | Restricts cookie to a URL path prefix |
priority | medium | low, medium, or high (non-standard, may be ignored) |
sameSite | — | 'lax', 'strict', 'none', true, or false |
secure | false | Only sent over HTTPS connections |