The staff layout shows customers Staff only. in place of its children. What does Asha get for the orders page, and what prints?
The tea shop's staff area has a layout that reads the session and, for anyone who isn't staff, renders <p>Staff only.</p> in place of {children}. The orders page under it lists every order with its address and logs when it does. Asha is a customer; Ravi works in the shop. What does each request get, and what does next start print?
app/layout.tsxexport const metadata = { title: "Leaf and Kettle" };
export default function RootLayout({ children }: LayoutProps<"/">) {
return (
<html lang="en">
<body>{children}</body>
</html>
);
}
lib/session.tsimport "server-only";
import { cookies } from "next/headers";
type User = { name: string; role: "customer" | "staff" };
// A stand-in for the sessions table: each cookie value names one signed-in person.
const sessions = new Map<string, User>([
["s-asha-7f3k", { name: "Asha", role: "customer" }],
["s-ravi-2m9q", { name: "Ravi", role: "staff" }],
]);
export async function getUser() {
const token = (await cookies()).get("session")?.value;
return token ? (sessions.get(token) ?? null) : null;
}
lib/orders.tsimport "server-only";
import { connection } from "next/server";
// A stand-in for the orders table, read for each request.
const orders = [
{ id: 1, tea: "Mint tea", address: "12 Lake Road" },
{ id: 2, tea: "Green tea", address: "4 Hill Street" },
{ id: 3, tea: "Oolong tea", address: "9 Mill Lane" },
];
export async function getAllOrders() {
await connection();
return orders;
}
app/staff/layout.tsximport { getUser } from "@/lib/session";
export const instant = false;
export default async function StaffLayout({ children }: LayoutProps<"/staff">) {
const user = await getUser();
if (user?.role !== "staff") return <p>Staff only.</p>;
return (
<section>
<h1>Staff area</h1>
{children}
</section>
);
}
app/staff/orders/page.tsximport { getAllOrders } from "@/lib/orders";
export default async function OrdersPage() {
const orders = await getAllOrders();
console.log(`orders page: listed ${orders.length} orders`);
return (
<ul>
{orders.map((order) => (
<li key={order.id}>
Order {order.id}: {order.tea} to {order.address}
</li>
))}
</ul>
);
}
It's a project create-next-app made (Next.js 16.4.3, TypeScript, the App Router, and Cache Components on) with these files, built with next build and run with next start. What happens:
- You run
next buildandnext start. - Asha, signed in with the cookie
session=s-asha-7f3k, opens/staff/orders. - A script sends Asha's cookie with
RSC: 1, asking for the page's RSC payload the way the router does. - Ravi, signed in with
session=s-ravi-2m9q, opens/staff/orders.
The answer
Work out what Next.js does at each step: what the build prints, what each request answers, and what the page shows. Then check.
Checking your sign-in…