Loading...
Loading...
DynamicServerError: Dynamic server usage: headers() expects to have requestAsyncStorageIn Next.js App Router, functions like headers(), cookies(), and searchParams are dynamic — they require a request context. If you call them in a page that Next.js tries to statically render, it throws this error.
Tell Next.js to always render this page dynamically (on every request).
// At the top of your page.tsx or layout.tsx
export const dynamic = 'force-dynamic';Only call headers()/cookies() in components that are explicitly dynamic.
import { cookies } from 'next/headers';
// This component will be dynamic
async function AuthCheck() {
const cookieStore = cookies();
const token = cookieStore.get('token');
return <div>{token ? 'Logged in' : 'Guest'}</div>;
}