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

Taught in

References