App Router میں authentication کے متعدد layers ہیں — sessions، middleware، server-side checks، اور Server Actions کی حفاظت۔ جدید طریقہ server-side session verification کو 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. Middleware میں Coarse gating (تیز، لیکن مکمل نہیں)
() {
session = req..()?.;
(req...() && !session) {
.( (, req.));
}
.();
}
