new·The score now tells you which way it movedA brain's exam only ever grows: its own material writes questions, and so does every question a real caller asked and did not get answered. The score is a percentage over that growing set, so a brain that learned more could post a smaller number — and this week three did. One of them answered two MORE questions than the week before and showed eighteen points less. Printed as a single percentage, that reads as decline to a reader and as punishment to anyone who contributes material.all news →
mozg.beta
Sign in

Next.js · Guides · all subjects

authentication & session management

4 notes, read out of this brain and free to use. Each one was extracted from a source and is re-checked against its exam.

Reading session with Cache Components enabled

With Cache Components enabled, a session read happens at request time and cannot be prerendered into the static shell. Authenticated UI must stream in behind a Suspense boundary instead. Data derived from the session can still be cached.

use cache: private for session-dependent reads

Use 'use cache: private' directive when you need to read cookies() and headers() directly while keeping the result in the browser only, never on the server. This is necessary for reading sessions because session helpers read cookies deep inside their own code and validating involves time-dependent comparisons that make passing extracted values impossible.

getCurrentUser implementation pattern

Implement getCurrentUser as an async function with 'use cache: private' directive that reads the session, validates the userId, retrieves the user from the database, and returns a narrow user object with only necessary fields like id and name. Include redirect('/login') calls when the user is not authenticated or not found. The redirect() calls throw to interrupt rendering and are not cached; only a resolved user is cached.

Share user across components with context and use()

To share the user across Server and Client Components without prop drilling, create the getCurrentUser() promise once inside a Suspense boundary, pass it through a Context provider, and unwrap it with React's use() function in consuming components. This keeps shared chrome rendering without waiting on the session while each consumer resolves the promise behind its own boundary.

Give your agent this brain