cookies()
The async function from next/headers that reads the request's cookies, and in Server Actions or Route Handlers can also set or delete them.
In more detail
In Next.js 15 you write const store = await cookies(). Server Components can only read: setting a cookie there throws, because headers may already have been sent while streaming.
Example
const store = await cookies();
store.set('session', token, { httpOnly: true, secure: true, sameSite: 'lax', maxAge: 60 * 60 * 24 * 7 });Related terms
- cookie — A small named value a server asks a browser to store and send back automatically on later matching requests.
- Dynamic APIs — Functions and props that depend on the incoming request, such as cookies(), headers() and searchParams, which make a route dynamic.
- Server Functions — Async functions marked with "use server" that run on the server but can be called from client components, for example as a form action.
Taught in
- Session Management: Secure Cookies & Token Validation — Next.js 15 & Modern App Router Architecture