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
- Find every import from
next/headers. In Server Components, route handlers, and server actions, writeconst cookieStore = await cookies()andconst headerList = await headers()before reading them. - If you wrap
cookies()in a helper (for examplecreateClientfor Supabase), make that helperasyncand await it at every call site:const supabase = await createClient(). - 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. - Don't try to call
cookies()orheaders()from a Client Component. Pass the values down from a Server Component, or read cookies in a route handler. - 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() };
}
cookies(), and don't mark the whole layout "use client" so you can read document.cookie instead.Copy-paste fix prompt
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.