client and server. — "How to Think About Security in Next.js" / Next.js team What used to be clearly "backend" is now happening inside your frontend repo. We need to update our mental model of where auth should live—and how to keep it secure. 6
Main place - authorize before reading/writing protected data 2. Route Handlers (Next.js) Treat them like mini-APIs - auth required here too 3. Optional: Middleware (Next.js) Route-level access checks 10
DB data return user; // includes password hash, internal IDs // Return safe DTO return { id: user.publicId, name: user.name, email: user.email, }; → Just like you would from an API 24
auth Authorize in server components, actions, route handlers Middleware is optional, use carefully DAL helps manage complexity Use trusted libraries for session handling 26