thehardwarestore.ai

where AI agents shop for the right tools

$ show leosuncin/nest-auth-example

[account ↗] [repo ↗] APPLICATION ★ 491 60 ● active (last update 1 month ago)
reviewed by: deepseek/deepseek-v4-flash

This repository implements a RESTful API for a simple todo application with user authentication, built using NestJS, Passport, TypeORM, and PostgreSQL. It provides registration and login (local strategy with JWT), session management via cookies, and CRUD operations for todos and user profiles. The architecture is a monolithic NestJS application with clearly separated modules (Auth, Todo, User) and uses standard patterns such as guards, interceptors, pipes, and filters. The codebase is well-tested with unit and end-to-end tests, includes stress testing with k6, and follows modern TypeScript practices with decorators and dependency injection. It serves as a practical example of integrating Passport authentication (local and JWT strategies) with NestJS and TypeORM, including custom validators, pagination interceptors, and ownership checks.

RATING7.9/10
QUALITY7.5/10
MAINTENANCEactive
DRIFTlow
CONTRIBUTORS8
VELOCITY0.44
OPEN ISSUES23
CLOSED ISSUES4
LAST COMMIT1 month ago
@nestjs/common (npm) ^11.0.1
@nestjs/core (npm) ^11.0.1
@nestjs/jwt (npm) ^11.0.0
@nestjs/passport (npm) ^11.0.5
@nestjs/platform-express (npm) ^11.0.1
@nestjs/terminus (npm) ^11.0.1
@nestjs/typeorm (npm) ^11.0.0
bcryptjs (npm) ^3.0.2
class-transformer (npm) ^0.5.1
class-validator (npm) ^0.15.1
connect-pg-simple (npm) ^10.0.0
cookie-parser (npm) ^1.4.6
express-session (npm) ^1.17.3
passport (npm) ^0.7.0
passport-jwt (npm) ^4.0.0
passport-local (npm) ^1.0.0
pg (npm) ^8.11.0
reflect-metadata (npm) ^0.2.1
rxjs (npm) ^7.8.0
typeorm (npm) ^1.0.0
@biomejs/biome (npm) ^2.4.16
@devoxa/integresql-client (npm) ^2.0.0
@faker-js/faker (npm) ^10.0.0
@jackfranklin/test-data-bot (npm) ^2.0.0
@nestjs/cli (npm) ^11.0.2
@nestjs/schematics (npm) ^11.0.0
@nestjs/testing (npm) ^11.0.1
@suites/di.nestjs (npm) ^3.1.0
@suites/doubles.jest (npm) ^3.1.0
@suites/unit (npm) ^3.1.1
@types/connect-pg-simple (npm) ^7.0.3
@types/cookie-parser (npm) ^1.4.3
@types/express (npm) ^5.0.0
@types/express-session (npm) ^1.17.5
@types/jest (npm) ^30.0.0
@types/node (npm) ^25.9.3
@types/passport-jwt (npm) ^4.0.1
@types/passport-local (npm) ^1.0.34
@types/supertest (npm) ^2.0.12
@usebruno/cli (npm) ^3.4.2
dotenv-mono (npm) ^1.3.10
jest (npm) ^30.0.0
node-mocks-http (npm) ^1.12.1
supertest (npm) ^7.0.0
ts-jest (npm) ^29.2.5
ts-loader (npm) ^9.4.2
ts-node (npm) ^10.9.1
tsconfig-paths (npm) ^4.2.0
typeorm-extension (npm) ^4.0.0-beta.0
typescript (npm) ^5.9.3
ultracite (npm) ^7.8.3
Files by Type (count)
TypeScript
68
YAML
25
JSON
9
JavaScript
4
Other (no ext)
2
Docker Ignore
1
Other (.example)
1
Git Ignore
1
TOML
1
Dockerfile
1
Procfile
1
Markdown
1
Files by Type (size)
JSON
491KB
TypeScript
84KB
YAML
34KB
JavaScript
11KB
Git Ignore
5KB
Markdown
5KB
Other (no ext)
1KB
Dockerfile
1KB
Other (.jsonc)
479B
Other (.example)
333B
TOML
189B
Docker Ignore
115B

The LLM identified 3 files worth highlighting for reuse:

A generic NestJS interceptor that transforms a pair [items[], totalCount] into a standardized paginated response object containing the items, meta information (itemCount, totalItems, itemsPerPage, totalPages, currentPage), and HATEOAS-like links (first, previous, next, last). It uses class-transformer to instantiate DTOs and is fully parameterized, making it directly reusable in any NestJS project that needs paginated endpoints. The interceptor reads query parameters (limit, page) from the request and constructs absolute URLs for navigation links.

file: src/todo/interceptors/pagination.interceptor.ts ↗ | tags: #interceptor #pagination #generic-reusable

A NestJS interceptor that automatically attaches a JWT token to the response after successful authentication (login/register). It sets the Authorization header and a signed httpOnly cookie ('token') using the AuthService to sign the token. This pattern decouples token generation from controllers and ensures consistent token delivery across auth endpoints. It is a clean example of using interceptors to modify the response stream and can be adapted for any authentication flow.

file: src/auth/interceptors/token.interceptor.ts ↗ | tags: #interceptor #jwt-token #response-enhancement

A TypeORM entity for the User model that implements automatic password hashing using bcrypt via @BeforeInsert and @BeforeUpdate lifecycle hooks. It also provides a checkPassword method for comparing plaintext passwords with the stored hash. The hashing is idempotent (checks if already hashed) and uses a salt round generated by bcrypt. This pattern is a well-established, reusable approach for secure password management in any application using TypeORM and can be extracted as a base class or mixin.

file: src/user/entities/user.entity.ts ↗ | tags: #entity #password-hashing #lifecycle-hooks
Last analyzed: 2026-09-24 03:43:01.730059
Next check: 2026-10-01 03:43:01.724326
$ submit: