Policies — Security · NestJS

Roles run out when the answer depends on the thing itself: a member of staff may rename the cat they adopted, nobody may delete an adopted cat. Describe abilities with CASL, check them in a guard for the route and in the service for the record.

What you will learn

Read the theory for Policies

All Security lessons

All NestJS courses

loading types…

What you'll learn

  • Say when a role is not enough: permissions that depend on the record being touched
  • Build an ability with CASL's AbilityBuilder: can and cannot, a subject class, conditions on its fields, and why a later cannot beats an earlier can
  • Check an ability against a subject type in a guard and against an instance in the service, and know what each answer means
  • Attach policies to routes with metadata and a guard that runs them all