Server Development / NestJS
Security
Authentication with Passport and JWT, and role-based authorization.
Authentication in NestJS
NestJS authentication is built from guards: one checks a password and issues a token, another verifies that token on every later request. This chapter wires Passport's local and JWT strategies into a Nest app, then protects every route by default with a global guard and a @Public() opt-out.
Authorization in NestJS
Once a NestJS request has a user, authorization decides what that user may do. This chapter builds role checks from a typed decorator and a guard, orders them after authentication, adds a @CurrentUser() parameter, and moves ownership checks into the service where the data is.