Cookie
Summary
Represents a HTTP cookie.
Supports parsing and serializing the cookie to/from Cookie and Set-Cookie headers.
Also supports cryptographic signing of the cookie value to ensure it's not tampered with, and secret rotation to easily rotate secrets without breaking existing cookies.
Signature
class Cookie {
constructor(name: string, options: CookieOptions): Cookie;
// Accessors
get domain(): string | undefined;
get expires(): Date | undefined;
get httpOnly(): boolean;
get maxAge(): number | undefined;
get name(): string;
get partitioned(): boolean;
get path(): string;
get sameSite(): SameSiteValue;
get secure(): boolean;
get signed(): boolean;
// Methods
parse(headerValue: string | null): Promise<string | null>;
serialize(value: string, props: CookieProperties): Promise<string>;
}
Constructor Params
name
The name of the cookie
options
Options for the cookie
Accessors
domain
The domain of the cookie.
expires
The expiration date of the cookie.
httpOnly
True if the cookie is HTTP-only.
maxAge
The maximum age of the cookie in seconds.
name
The name of the cookie.
partitioned
True if the cookie is partitioned.
path
The path of the cookie.
sameSite
The SameSite attribute of the cookie.
secure
True if the cookie is secure (only sent over HTTPS).
signed
True if this cookie uses one or more secrets for verification.
Methods
parse(headerValue: string | null): Promise<string | null>
Extracts the value of this cookie from a Cookie header value.
headerValue
The Cookie header to parse
serialize(value: string, props: CookieProperties): Promise
Returns the value to use in a Set-Cookie header for this cookie.
value
The value to serialize
props
Additional properties to use when serializing the cookie