Authentication in the App Router spans several layers — sessions, middleware, server-side checks, and protecting Server Actions. The modern approach favors server-side session verification over client-only checks.
Session strategy
Cookie-based sessions (httpOnly cookie):
✓ Store a signed session id or encrypted JWT in an httpOnly, secure cookie
✓ httpOnly = not readable by JavaScript → protects against XSS token theft
✓ Use a library: Auth.js (NextAuth), Clerk, Lucia, or a custom solution
1. Coarse gating in middleware (fast, but not the whole story)
() {
session = req..()?.;
(req...() && !session) {
.( (, req.));
}
.();
}
