Skip to main content
cookies is an async function that lets you read incoming request cookies in Server Components, and read or write outgoing cookies in Server Functions and Route Handlers.
app/page.tsx

Methods

The object returned by cookies() exposes the following methods:
{ name: string; value: string } | undefined
Returns the first cookie with a matching name. Returns undefined if not found.
{ name: string; value: string }[]
Returns all cookies with a matching name. If name is omitted, returns all cookies.
boolean
Returns true if a cookie with the given name exists.
void
Sets an outgoing cookie. Only available in Server Functions and Route Handlers.
void
Deletes a cookie by name. Only available in Server Functions and Route Handlers.
string
Returns a string representation of the cookies.
When calling set(), the following options are supported:
string
The cookie name.
string
The cookie value.
Date
The exact expiration date.
number
Cookie lifetime in seconds.
string
The domain on which the cookie is available.
string
default:"/"
Restricts the cookie to a specific path within the domain.
boolean
If true, the cookie is only sent over HTTPS.
boolean
If true, the cookie is inaccessible to client-side JavaScript.
'lax' | 'strict' | 'none' | boolean
Controls cross-site request behavior.
'low' | 'medium' | 'high'
The cookie priority hint.
boolean
Whether the cookie uses CHIPS partitioning.

Good to know

  • cookies is async and returns a promise. Use async/await or React’s use.
  • In Next.js 14 and earlier, cookies was synchronous. Synchronous access still works in Next.js 15 for backwards compatibility, but is deprecated.
  • cookies is a Request-time API. Using it in a layout or page opts the route into dynamic rendering.
  • delete and set can only be called inside a Server Function or Route Handler — not during Server Component rendering.
  • HTTP does not allow setting cookies after streaming starts, so set must be used in a Server Function or Route Handler.

Examples

app/page.tsx

Getting all cookies

app/page.tsx
app/actions.ts
app/page.tsx

Deleting cookies

app/actions.ts

Version history