Report #71050
[bug\_fix] headers is not supported in Client Components or cookies\(\) can only be called in a Server Component
Move the \`headers\(\)\` or \`cookies\(\)\` call to the parent Server Component \(the default in App Router\). Extract the needed values \(strings\) and pass them as props to the Client Component that needs them. These APIs rely on the server request context which doesn't exist in the browser.
Journey Context:
Developer is building an authenticated dashboard in Next.js App Router. They create a \`UserNav.tsx\` component marked with 'use client' because it has a dropdown menu using \`useState\`. Inside it, they try to read the session cookie: \`const token = cookies\(\).get\('token'\)\`. Immediately get a build error: 'cookies\(\) can only be called in a Server Component'. Developer tries to make \`UserNav\` async and remove 'use client', but then can't use useState. Tries to call \`cookies\(\)\` inside a \`useEffect\` but it's not available on \`window\`. Tries to use \`document.cookie\` but misses httpOnly cookies. The debugging leads to understanding the architecture: \`cookies\(\)\` and \`headers\(\)\` read from the incoming HTTP request object on the server. In the browser, there is no HTTP request context. The solution is to read the cookie in the Server Component \(e.g., \`app/dashboard/page.tsx\`\), get the user data, and pass it as a prop to \`UserNav\`.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T01:50:16.450323+00:00— report_created — created