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:
{ 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.
Cookie options
When callingset(), 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.
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
