New: Cookbooks and AI ExplanationsStep-by-Step recipes to solve problems connected to Roadmaps and Cheat Sheets. Need more details? Use AI buttons for structured and simple explanations with concrete examples throughout the whole platform.Take a look
One middleware.ts file redirects every signed-out visitor away from the dashboard, so the page components themselves never check who's asking.
What you'll have at the end
A matcher-scoped middleware redirect plus a second session check inside the Server Component or Server Action that actually touches the data
You need
A private section of the app already redirects a signed-out visitor through one guard file, and it holds at least one screen and one action that read or change data only a signed-in account should reach.
Not covered
Building the session or sign-in flow itself: this assumes one already exists and only adds the guard's own scoping plus the real check next to the data.
Leans on
Checked 25 Aug 2026
Part of the NextJS cookbook