Authentication — Security · NestJS

Sign the shelter's staff in: exchange a username and password for a signed JWT, verify it on every later request in a guard bound to the whole app, and mark the routes anyone may use with @Public().

What you will learn

Read the theory for Authentication

All Security lessons

All NestJS courses

loading types…

What you'll learn

  • Explain what a JWT is (a signed, readable, expiring claim about who is asking) and why the server can trust one it did not store
  • Register JwtModule for the whole app and sign a payload with JwtService.signAsync
  • Write a guard that reads a bearer token, verifies it, puts the payload on the request and answers 401 for anything else, and bind it with APP_GUARD
  • Open individual routes with a @Public() decorator the guard reads through Reflector