Protected dashboard
What you need to know
A protected dashboard should obtain a verified identity on the server for each relevant access decision, then read only data that the identity is allowed to see.
By the end, you can: verify anonymous and authenticated access; avoid trusting client state.
Protect a page using a verified data boundary
// app/dashboard/page.tsx — integration outline, adapter requiredimport {redirect} from 'next/navigation';import {verifySession,listOwnedBooks} from '../../lib/approved-auth-dal';export default async function Page() { const principal=await verifySession(); if(!principal) redirect('/sign-in'); const books=await listOwnedBooks(principal.id); return <main><h1>Your reading list</h1><ul> {books.map(book=><li key={book.id}>{book.title}</li>)} </ul></main>;}Expected behavior: Anonymous visitors are redirected; verified readers see only their own titles if the adapter enforces its contract. The adapter is intentionally not implemented as a real authentication service.
How it works
In App Router use a server-side data access layer to verify session and scope each read. A page can redirect an anonymous visitor to a sign-in route, but the operation reading or writing a record must enforce its own rule. Layout or Proxy checks can provide early navigation feedback; neither is a substitute for authorization in Route Handlers and Server Functions. A session is not a public cache key. Avoid sharing personalized results through a persistent public cache, and return a minimal DTO containing only needed data. In an API, distinguish unauthenticated (401) from forbidden (403) or deliberately concealed missing resources (404). Return an appropriate private/no-store policy for sensitive responses. The examples below are adapter contracts only: verifySession means an independently reviewed provider integration, not a stub that trusts a browser ID. The actual runtime fixture uses no login route or cookies, only isolated synthetic test data.
Protect a separate API contract
// app/api/dashboard/route.ts — same adapter requiredimport {verifySession,listOwnedBooks} from '../../../lib/approved-auth-dal';export async function GET() { const principal=await verifySession(); const headers={'Cache-Control':'private, no-store'}; if(!principal) return Response.json({error:'Sign in required'},{status:401,headers}); const books=await listOwnedBooks(principal.id); return Response.json(books.map(b=>({id:b.id,title:b.title})),{headers});}Expected behavior: Anonymous API calls receive 401; authorized requests return projected titles without exposing internal fields. Actual response behavior remains staged.
Common mistake
Do not pass userId from a query string to a private repository or assume a hidden button protects an endpoint. Check each direct request against the verified principal and the resource. Do not expose private data in a shared cache.
Practice and verification
Create a test matrix for anonymous, reader A, reader B, expired session and revoked session. Check direct page and API calls, response fields and cache policy separately. Run the offline session and owner-scope fixture now; browser and auth-provider integration are pending.
Scope: App Router, proposed Next.js 16.x, React 19 family, Cache Components disabled. Framework snippets are static or explicitly partial; actual browser, auth and generated-route checks are pending. SQLite exercises run separately in the authoring environment, not the ByteMind evaluator.