Xác thực trong App Router trải qua nhiều lớp — session, middleware, kiểm tra phía server, và bảo vệ Server Actions. Cách tiếp cận hiện đại ưu tiên xác minh session phía server hơn là kiểm tra chỉ ở client.
Chiến lược session
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. Chặn thô trong middleware (nhanh, nhưng chưa phải tất cả)
() {
session = req..()?.;
(req...() && !session) {
.( (, req.));
}
.();
}
