[]previous and next page

serializeCookie

Builds a Set-Cookie value.

Builds a Set-Cookie value. Secure by default: HttpOnly; Secure; SameSite=Lax; Path=/. Names, domains and paths are validated, so no attribute can inject another or a header line.

Import#

ts
import { serializeCookie } from "@shadow-js/dusk/server";

Signature#

ts
function serializeCookie(name: string, value: string, options: CookieOptions = {}): string

Parameters#

Name Description
name Cookie name (an RFC 6265 token).
value Any string; it is percent-encoded.
options Attributes.

Returns#

The header value.

Throws#

  • TypeError for an invalid name, domain, path or a prefix rule violation (__Host-, __Secure-, SameSite=None without Secure). RangeError for a cookie over 4096 bytes.

Examples#

ts
serializeCookie("theme", "dark", { maxAge: 31_536_000, httpOnly: false });