NestJS login with JWT, validation and Redis cache (Part 8b)
Sadman Sakib
0:00 / 0:00
NestJS login with JWT, validation and Redis cache (Part 8b)
19 просмотров · 4 дн. назад
Sadman Sakib
805 подписчиков
19 просмотров · 4 дн. назад
LINUX FROM ZERO, PART 8b: NestJS login with JWT, validation and a Redis cache #nestjs #jwt #redis
Today PhotoWall's API learns to say no, and to remember. Bad input gets a clear 400 answer (DTOs with class-validator, a global ValidationPipe with whitelist and forbidNonWhitelisted, and every status code as a waiter's answer). Passwords are stored the right way with argon2: two users with the same password get two different hashes, and we read a hash piece by piece (argon2id, memory, passes, the salt). Login hands out a JWT, decoded on screen with base64: anyone can read it, only the secret's stamp makes it real. A guard written by hand checks the token on POST and DELETE (401 without a token, 401 with a fake one), and the user id comes from the token, never from the request body. Redis becomes a cache inside the API (cache-aside with ioredis, a stale cache on purpose, and DEL on every write) and a login limit (five wrong passwords, then 429). And an end-to-end test checks the doorman after every change. Every chapter ends with a quick quiz.
The course so far:
1. Linux from zero: computers, Linux and the terminal
2. Be the boss of your Linux: users, sudo, permissions, apt, services, logs, SSH
3. How the internet works: IP addresses, routers, DNS, ports, HTTPS
4. Your own web server: nginx, reverse proxy, ufw, HTTPS
5. A real firewall: OPNsense and a WireGuard VPN
6. Docker: containers, images, volumes, networks, Compose
7. Data: PostgreSQL and Redis
8a. Your first REST API with NestJS
8b. NestJS login, validation and a Redis cache (this video)
9. File storage with S3 (next)
🔗 Links
Parts 1 to 8a of the course: / @sadmansakib
NestJS docs: validation (ValidationPipe, whitelist): https://docs.nestjs.com/techniques/va...
NestJS docs: authentication: https://docs.nestjs.com/security/auth...
NestJS docs: guards: https://docs.nestjs.com/guards
class-validator: https://github.com/typestack/class-va...
argon2 for Node.js: https://github.com/ranisalt/node-argon2
OWASP Password Storage Cheat Sheet: https://cheatsheetseries.owasp.org/ch...
Introduction to JSON Web Tokens (jwt.io): https://jwt.io/introduction
@nestjs/jwt: https://github.com/nestjs/jwt
ioredis, the Redis client: https://github.com/redis/ioredis
Redis docs: EXPIRE (NX): https://redis.io/docs/latest/commands...
Vitest: https://vitest.dev
supertest: https://github.com/forwardemail/super...
VS Code in the browser (openvscode-server): https://github.com/gitpod-io/openvsco...
⏱️ Chapters
0:00 Welcome
1:55 Bad input gets a clear answer
7:10 Passwords the right way
13:29 Login with a JWT and a doorman
24:53 Redis: a cache and a login limit
33:35 A robot taster: tests
35:31 Recap & homework
Everything in this video really ran: NestJS 12, class-validator 0.15, argon2 0.45, @nestjs/jwt 12, ioredis 6, Vitest 4 and supertest, on Node.js 26 in Docker 29 (the official node:26-slim image) next to PostgreSQL 17 and Redis 8.10, on Ubuntu 26.04 in a virtual machine on my Mac (an ARM computer, so everything is arm64), with real terminal output (October 2026). VS Code is the open-source VS Code in the browser, running as a container in that virtual machine. The passwords, the JWT secret, the tokens and every name and email you see are practice values for this lab only; part 11 moves the real secrets into a vault. The NestJS docs now also teach a newer official package, @nestjs/authentication; this video writes the guard by hand with @nestjs/jwt, so every step is visible. The pretty JSON in the terminal comes from jq: sudo apt install jq.
The narration is my own voice, recreated with AI from a recording of me.
Subscribe for part 9 and the whole course: https://www.youtube.com/@sadmansakib?...
#nestjs #jwt #linuxforbeginners