Authentication and authorization in NestJS, done properly: hashed passwords, JWTs, Redis-backed sessions and role guards on top of PostgreSQL + Prisma.
It also includes a step-by-step tutorial in tutorial/ that explains how each part was built.
- User registration and login with bcrypt password hashing
- JWT access tokens (configurable expiry)
- Session storage and validation in Redis
- Role-based access control with guards, plus
@Public(),@Roles()and@User()decorators - Prisma ORM on PostgreSQL
NestJS · TypeScript · Prisma · PostgreSQL · Redis · Passport JWT · Docker Compose
- Setup and fundamentals
- Password security
- JWT tokens deep dive
- Session management
- Authentication flow
- Authorization and guards
- Advanced features
- Production ready
| Method | Path | Description |
|---|---|---|
POST |
/users |
Register |
POST |
/users/login |
Log in |
GET |
/users/me, /users/profile |
Current user |
GET |
/users, /users/:id |
List / get users |
PATCH |
/users/:id |
Update a user |
docker compose up -d # Postgres + Redis
npm install
npx prisma migrate dev
npm run start:devEnvironment variables: DATABASE_URL, JWT_SECRET, JWT_EXPIRES_IN, REDIS_HOST, REDIS_PORT, REDIS_PASSWORD, PORT.