Documentation Index
Fetch the complete documentation index at: https://mintlify.com/dvlkit/nuxe/llms.txt
Use this file to discover all available pages before exploring further.
useCookie provides a unified, isomorphic API for reading and writing browser cookies. On the server it parses the incoming Cookie request header; on the client it reads from document.cookie. Setting the returned Ref’s .value on the client automatically serializes and writes the cookie back to document.cookie using the options you supplied.
useCookie returns a reactive Ref. Assigning undefined to its .value removes the cookie by setting Max-Age=-1. Any other assignment serializes the new value and writes it to document.cookie.Signature
Parameters
The name of the cookie to read and write.
Standard cookie attributes applied when writing the cookie on the client.
Maximum cookie lifetime in seconds (sets
Max-Age). Use 0 or a negative value to delete the cookie immediately.Absolute expiry date (sets
Expires). maxAge takes precedence if both are supplied.Marks the cookie as
HttpOnly, preventing client-side JavaScript from reading it. Setting this to true via useCookie on the client has no practical effect because JavaScript cannot set HttpOnly cookies — it must be set by the server in a Set-Cookie response header.Marks the cookie as
Secure, restricting it to HTTPS connections.Controls cross-site request behavior.
'lax' is the browser default for most cookies. Use 'none' with secure: true for third-party cookie contexts.The domain scope of the cookie. Defaults to the current host without a leading dot, meaning subdomains are excluded unless you set this explicitly.
The URL path scope of the cookie. Defaults to
/ when omitted from the Set-Cookie header, but serializeCookie does not add a Path automatically unless you supply one.Return Values
A reactive
Ref whose value is the decoded cookie string, or undefined if the cookie does not exist. Assigning a new string to .value writes the cookie; assigning undefined deletes it by setting Max-Age=-1.Utility Functions
parseCookieValue
Parses a single named cookie from a raw Cookie header string.
The raw value of the
Cookie HTTP header (e.g. "session=abc; theme=dark").The name of the cookie to extract.
undefined if the name is not present.
serializeCookie
Builds a Set-Cookie-compatible string from a name, value, and options.
Cookie name. URL-encoded automatically.
Cookie value. URL-encoded automatically.
Same
CookieOptions as useCookie. Attributes are appended in the order: Max-Age, Expires, Path, Domain, SameSite, Secure, HttpOnly.