Quickstart — Next.js
A minimal Next.js (App Router) app with SSR auth.
Authenticated server components and route handlers, on top of the backend quickstart.
1. Set up
2. The auth helpers
accessTokenType: 'cookie' means the backend sets HttpOnly cookies that Next.js can read server-side.
3. The root layout
getServerAuth reads cookies, calls /auth/verify-session, and gives you a hydration-ready snapshot. The first render is fully authenticated.
4. A protected server component
5. A protected API route
6. Middleware redirects
7. Login page
Same <LoginPage> from the React quickstart — useNestAuth().login(...) works identically.
8. Run it
Open http://localhost:3000/dashboard, get redirected, sign in, get redirected back.
What's next
- Next.js helpers — full
createNextAuthHelpersreference. - Cross-tab sync.
- Next.js protected dashboard recipe.