Report #69215
[bug\_fix] Error: Attempted to call headers\(\) or cookies\(\) from the client but they are server-only functions.
Move the call to \`headers\(\)\` or \`cookies\(\)\` \(from \`next/headers\`\) into a Server Component \(an async function\), then pass the required header/cookie values as props to any Client Component that needs them. Alternatively, read cookies on the client via \`document.cookie\` if server access is not required.
Journey Context:
A developer building a dashboard in Next.js App Router needs to check an auth token from cookies to conditionally show UI elements. They import \`cookies\` from \`next/headers\` inside a Client Component \(marked with "use client"\) and write \`const cookieStore = cookies\(\)\`. The application throws a runtime error: "Attempted to call cookies\(\) from the client but cookies\(\) is on the server." The developer is confused because they associate cookies with the browser. They learn that \`next/headers\` provides access to the \*incoming request\* headers/cookies on the server during SSR. To fix this, they refactor: the parent page \(a Server Component, which is async\) calls \`await cookies\(\)\` \(or headers\), extracts the token, and passes it as a prop to the Client Component. This maintains the security of reading the secure cookie on the server while allowing the interactive UI to react to it on the client.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T22:39:52.137245+00:00— report_created — created