Next.jsAuth

Next.js: cookies() / headers() should be awaited

`cookies()` should be awaited before using its value. Learn more: https://nextjs.org/docs/messages/sync-dynamic-apis

In short: In Next.js 15+, cookies(), headers(), and draftMode() from next/headers return Promises and must be awaited.

Why it happens

These helpers used to be synchronous. Next.js 15 made them async so the framework can delay reading the request. AI snippets and older Supabase/Auth examples still write const cookieStore = cookies(); cookieStore.getAll(). On Next.js 15 and 16 that is wrong: you need const cookieStore = await cookies() before you call get, getAll, or set. The same change applies to headers() and draftMode(). This often shows up first in a Supabase server client or in middleware-adjacent auth helpers copied from a pre-15 tutorial.

How to fix it

  1. Find every import from next/headers. In Server Components, route handlers, and server actions, write const cookieStore = await cookies() and const headerList = await headers() before reading them.
  2. If you wrap cookies() in a helper (for example createClient for Supabase), make that helper async and await it at every call site: const supabase = await createClient().
  3. In Next.js 15+, cookies().set(...) also needs the awaited store: (await cookies()).set(...). Setting cookies in a Server Component can still throw; prefer a route handler, server action, or middleware for writes.
  4. Don't try to call cookies() or headers() from a Client Component. Pass the values down from a Server Component, or read cookies in a route handler.
  5. Rebuild and hit a signed-in page. The await warning should be gone, and auth helpers that read cookies should see the session again.

Example

import { cookies } from "next/headers";

export async function createClient() {
  const cookieStore = await cookies();
  return { getAll: () => cookieStore.getAll() };
}
Don't: Don't downgrade Next.js only to keep synchronous cookies(), and don't mark the whole layout "use client" so you can read document.cookie instead.

Copy-paste fix prompt

3 · The fix promptPaste into Cursor, Claude Code, Codex, Lovable, Bolt, Replit or v0
I'm getting this error in my app:

`cookies()` should be awaited before using its value. Learn more: https://nextjs.org/docs/messages/sync-dynamic-apis

[Paste the full error, stack trace, and the file it points to here]

Likely cause: In Next.js 15+, cookies(), headers(), and draftMode() from next/headers return Promises and must be awaited.

Task: Find every cookies(), headers(), and draftMode() call from next/headers and await them (and any helper that wraps them). Update call sites to await the helper. Don't use these APIs in Client Components.

Rules:
- First explain the root cause in 2 sentences and list the files you'll change.
- Make the smallest change that fixes it. Don't refactor unrelated code.
- Don't disable security or checks (RLS, auth, signature verification, type checking, CORS allow-all) to make the error disappear.
- Never print or hard-code secret keys.
- Finish by telling me exactly how to verify the fix.

Common with: Cursor, v0, Claude Code, Codex. Last reviewed 2026-11-15.

Related fixes

← All fixes · Still stuck? Use the diagnose-first prompt