Guards — Basics · NestJS

Decide who may call a handler with a guard that reads role metadata off the handler through the Reflector, and answer 401 or 403 depending on why.

What you will learn

Read the theory for Guards

All Basics lessons

All NestJS courses

loading types…

What you'll learn

  • Implement CanActivate and choose between returning false and throwing, and what the client gets for each
  • Read handler metadata in a guard with the Reflector and a decorator made by Reflector.createDecorator
  • Bind a guard to a controller with @UseGuards and mark individual handlers with a metadata decorator