Skip to content

πŸ” NestJS Fastify Auth – Secure, full-featured auth system built with NestJS, Fastify, PostgreSQL, and Prisma. Supports JWT, OAuth, and OTP login with both GraphQL and REST APIs.

Notifications You must be signed in to change notification settings

sheharyarIshfaq/NestJS-Fastify-Auth

Repository files navigation

NestJS Fastify Authentication System

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.


Features

Authentication & User Management

  • βœ… 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).

Security Features

  • πŸ”’ 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.

API & Backend Architecture

  • πŸš€ 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.

Cloud Integrations

  • ☁️ Google Cloud Storage – Securely handles file uploads.
  • πŸ“§ SendGrid Email Service – OTP & account recovery email handling.

Setup & Installation

1️⃣ Clone the repository

git clone https://github.com/yourusername/nestjs-fastify-auth.git
cd nestjs-fastify-auth

2️⃣ Install dependencies

npm install

3️⃣ Setup environment variables

  • Copy .env.example to .env and update values (database, JWT secrets, OAuth keys, etc.).

4️⃣ Run the application

npm run start:dev

Testing the API

πŸ“Œ Postman Workspace – Pre-configured API requests:
πŸ”— Postman Collection

πŸ“Œ Run API Tests with Jest

npm run test

Tech Stack

βœ… 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. πŸš€

About

πŸ” NestJS Fastify Auth – Secure, full-featured auth system built with NestJS, Fastify, PostgreSQL, and Prisma. Supports JWT, OAuth, and OTP login with both GraphQL and REST APIs.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published