Read request cookies
Read preferences, feature flags, or session identifiers during server rendering.
Next.js 16+ · Function
cookies is an asynchronous Next.js function for reading incoming request cookies in Server Components and reading or writing outgoing cookies in Server Functions or Route Handlers. Await it to access the cookie store.
Import cookies from next/headers and await it to obtain a cookie store. The store reads incoming cookies in Server Components and can read or modify outgoing cookies in Server Functions or Route Handlers. Use get, getAll, has, set, delete, and toString as appropriate.
const cookieStore = await cookies()| Name | Type | Description |
|---|---|---|
name | string | Cookie name used by get, getAll, has, or delete. |
value | string | Value for the cookie being written. |
options | object | Cookie attributes such as path, secure, httpOnly, sameSite, maxAge, or expires. |
A promise that resolves to a cookie store supporting get, getAll, has, set, delete, and toString.
cookies to read request cookies in Server Components.getAll(name) returns every matching cookie; omit the name to retrieve all cookies.has(name) checks whether a named cookie exists.set(name, value, options) writes a cookie with configurable options.delete(name) removes a named cookie.cookies is asynchronous, call it with await or React's use function.import { cookies } from 'next/headers'
export default async function Page() {
const cookieStore = await cookies()
const theme = cookieStore.get('theme')?.value ?? 'light'
return <p>Theme: {theme}</p>
}This Server Component awaits the cookie store and reads the value of the theme cookie, falling back to light.
Read preferences, feature flags, or session identifiers during server rendering.
Persist authentication or user-preference state from a Server Function.
Remove a session or preference cookie from a Server Function or Route Handler.
next/headersServer ComponentsServer FunctionsRoute Handlersuse