Accounts and roles — Capstone: the shelter service · NestJS

Give the shelter its people: accounts with hashed passwords in the database, sign-in with a JWT, a guard in front of every route with a few marked public, staff-only changes to the cats, adoptions made as whoever is signed in, and the database's own refusals turned into answers a client can use.

What you will learn

Read the theory for Accounts and roles

All Capstone: the shelter service lessons

All NestJS courses

loading types…

What you'll learn

  • Store users with bcrypt hashes, at a cost read from configuration, and seed a staff account on the first start
  • Sign users in with a JWT whose secret comes from configuration, and protect every route with a global guard that a @Public() decorator opens
  • Restrict routes by role with a second global guard reading @Roles() metadata
  • Take the acting user from the token rather than the request body, and map a database's unique-constraint error to a 409 with an exception filter