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 gives you a unified reactive API for cookies that works identically during SSR and in the browser. On the server it reads from the incoming Cookie request header; on the client it reads document.cookie and installs a watcher that writes back to document.cookie whenever the ref value changes. The result is a single ref you can bind to form controls or update programmatically without thinking about the environment.
useCookie
Signature
The cookie name. Used as-is to match against the
Cookie header on the server and against document.cookie on the client.Optional attributes applied when writing the cookie on the client. See CookieOptions below.
Ref<string | undefined> is:
undefinedwhen the cookie is absent.stringwith the decoded cookie value when present.
undefined to the ref removes the cookie by setting Max-Age=-1.
Example — persisting a theme preference
theme.value, which the watcher immediately serializes into document.cookie. On the next page load the server reads the Cookie header and useCookie initializes with the persisted value.
Example — session cookie
CookieOptions
All seven fields are optional. They are appended to theSet-Cookie string in the order: Max-Age, Expires, Path, Domain, SameSite, Secure, HttpOnly.
Number of seconds until the cookie expires. Takes precedence over
expires in most browsers. Setting this to a negative number removes the cookie.Exact
Date at which the cookie expires. Use maxAge when you want a relative TTL; use expires when you need a fixed timestamp.When
true, the cookie is flagged HttpOnly — it is sent with requests but is not accessible via JavaScript (document.cookie). Only meaningful for cookies set by server-side code.When
true, the cookie is only sent over HTTPS connections.Controls when the cookie is sent with cross-site requests.
'strict'— only sent on same-site requests.'lax'— sent on same-site requests and top-level navigations.'none'— sent on all requests; requiressecure: true.
Restricts the cookie to the specified domain and its subdomains (e.g.
'example.com').Restricts the cookie to the specified path prefix (e.g.
'/' for the whole site or '/app' for a sub-path). Defaults to the current path in browsers when omitted.SSR behavior
Server reads the request header
When
useCookie is called during SSR, Nuxe reads the Cookie header from the incoming HTTP request and parses the named cookie using parseCookieValue. The ref is initialized with that value (or undefined if the cookie is absent).Component renders with the correct value
Because the ref is populated before the template renders, the initial HTML reflects the real cookie value — no flash of incorrect content.
Low-level helpers
These functions are exported for cases where you need to work with cookie strings directly — for example, in server middleware or custom response handlers.parseCookieValue
Parses a single named cookie out of a rawCookie header string.
undefined is returned.
serializeCookie
Serializes a cookie name, value, and options into aSet-Cookie header string.
encodeURIComponent. Options are appended in the order: Max-Age, Expires, Path, Domain, SameSite, Secure, HttpOnly.
Cookies marked
httpOnly are set by server-side handlers (e.g. Set-Cookie response headers from your API routes) and are intentionally invisible to document.cookie. Because useCookie reads document.cookie on the client, it will always see undefined for httpOnly cookies — this is expected browser security behavior, not a Nuxe limitation. Use useCookie for client-accessible cookies and manage httpOnly session tokens entirely within your server routes.