This is a scalable and secure authentication system built with NestJS and Fastify, designed for multi-platform compatibility (web and mobile) while maintaining high performance and security best practices. The project supports GraphQL and REST APIs, integrates OAuth authentication, and follows a modular, well-structured architecture for maintainability and scalability.
- β Email/Password Authentication β Secure login & registration using bcrypt.
- β OTP-Based Login & Password Recovery β Time-limited, single-use OTPs sent via email.
- β Google & Facebook OAuth 2.0 β Secure social login via Passport.js strategies.
- β
JWT Authentication & Token Management
- Access Token: 15 min expiration
- Refresh Token: 7 days expiration
- Includes Role-Based Access Control (RBAC) (user, admin).
- π Rate Limiting β Protects against brute-force attacks.
- π CORS & CSRF Protection β Secures cross-origin requests.
- π Input Validation & Sanitization β Prevents SQL injection & XSS attacks.
- π HTTPS Support β Configured for secure API communications.
- π GraphQL API for Queries & Mutations β Optimized for fetching structured data.
- π REST API for File Uploads & Miscellaneous Endpoints β Handles efficient file management.
- π Versioned API Endpoints β Ensures backward compatibility (e.g.,
/v1/login
). - π PostgreSQL with Prisma ORM β Structured database with optimized schema.
- π Admin Panel β User management, data exports, and system monitoring.
- βοΈ Google Cloud Storage β Securely handles file uploads.
- π§ SendGrid Email Service β OTP & account recovery email handling.
git clone https://github.com/yourusername/nestjs-fastify-auth.git
cd nestjs-fastify-auth
npm install
- Copy
.env.example
to.env
and update values (database, JWT secrets, OAuth keys, etc.).
npm run start:dev
π Postman Workspace β Pre-configured API requests:
π Postman Collection
π Run API Tests with Jest
npm run test
β
NestJS + Fastify β High-performance backend framework.
β
PostgreSQL + Prisma β Efficient database management.
β
GraphQL + REST API β Flexible & scalable API structure.
β
Passport.js β Secure OAuth authentication.
β
SendGrid + Google Cloud Storage β Reliable email & cloud storage integration.
This project ensures scalability, security, and maintainability, making it ideal for real-world production-ready authentication systems. π