Documentation Index
Fetch the complete documentation index at: https://mintlify.com/vercel/next.js/llms.txt
Use this file to discover all available pages before exploring further.
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 bycookies() exposes the following methods:
Returns the first cookie with a matching name. Returns
undefined if not found.Returns all cookies with a matching name. If
name is omitted, returns all cookies.Returns
true if a cookie with the given name exists.Sets an outgoing cookie. Only available in Server Functions and Route Handlers.
Deletes a cookie by name. Only available in Server Functions and Route Handlers.
Returns a string representation of the cookies.
Cookie options
When callingset(), the following options are supported:
The cookie name.
The cookie value.
The exact expiration date.
Cookie lifetime in seconds.
The domain on which the cookie is available.
Restricts the cookie to a specific path within the domain.
If
true, the cookie is only sent over HTTPS.If
true, the cookie is inaccessible to client-side JavaScript.Controls cross-site request behavior.
The cookie priority hint.
Good to know
cookiesis async and returns a promise. Useasync/awaitor React’suse.- In Next.js 14 and earlier,
cookieswas synchronous. Synchronous access still works in Next.js 15 for backwards compatibility, but is deprecated. cookiesis a Request-time API. Using it in a layout or page opts the route into dynamic rendering.deleteandsetcan 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
setmust be used in a Server Function or Route Handler.
Examples
Getting a cookie
app/page.tsx
Getting all cookies
app/page.tsx
Setting a cookie
app/actions.ts
Checking if a cookie exists
app/page.tsx
Deleting cookies
- delete()
- Empty value
- maxAge: 0
app/actions.ts
Version history
| Version | Changes |
|---|---|
v15.0.0-RC | cookies is now async. A codemod is available. |
v13.0.0 | cookies introduced. |
