Passport — Security · NestJS

The same sign-in, the way most of the Node world writes it: Passport strategies for the password check and for the bearer token, wrapped by @nestjs/passport into guards, and a guard that answers a strategy's refusal with the right status.

What you will learn

Read the theory for Passport

All Security lessons

All NestJS courses

loading types…

What you'll learn

  • Describe what a Passport strategy is (a way of finding credentials in a request plus a verify step) and what @nestjs/passport turns it into (a guard)
  • Write a local strategy whose validate() checks a username and password, and a JWT strategy configured to read a bearer token with a secret and an expiry
  • Override handleRequest() in a guard that extends AuthGuard(), and explain why the default answers every strategy failure with a 401
  • Wire strategies as providers, PassportModule as an import, and a global JWT guard that honours @Public()