Next.js Discord

Discord Forum

cookies in layout

Unanswered
Japanese common catfish posted this in #help-forum
Open in Discord
Japanese common catfishOP
I have a simple layout like this:
import { cookies } from "next/headers";
import { redirect } from "next/navigation";
import type { ReactNode } from "react";

export default async function ({ children }: { children: ReactNode }) {
    const cookieStore = cookies();
    console.log(cookieStore);
    if (!cookieStore.get("hanko")) redirect("/auth");

    return <section>{children}</section>;
}


When I remove the cookies invocation, it works fine. Is it not allowed in a layout.tsx file?

3 Replies

Japanese common catfishOP
Using next 13.4.19.
Does it happen also when you force the route to be dynamic like so?
export const dynamic = 'force-dynamic'
The only thing that cookies does, aside from it's obvious purpose, is it forces the route to be dynamically rendered at request time.