Skip to content

Latest commit

 

History

History
90 lines (66 loc) · 2.72 KB

File metadata and controls

90 lines (66 loc) · 2.72 KB

AuthProject

Production-ready full-stack authentication system built as a monorepo. The backend implements a security architecture I call Centralized Truth — every API response message, HTTP status code, and Swagger documentation point is driven by a single constants system, so docs and implementation are mathematically guaranteed to stay in sync.

Built with NestJS + Next.js 15. Focused on getting the hard parts of auth right: cryptographic OTPs, refresh token rotation, forensic audit logging, and zero documentation drift.


What makes this different

Most auth implementations scatter response strings across controllers, DTOs, and tests. When you change a message, something breaks silently. Centralized Truth solves this:

ResponseMessages.AUTH.INVALID_OTP
  → used in controller logic
  → used in Swagger @ApiResponse decorator
  → used in test assertions

Change the constant once. Logic, docs, and tests all update automatically.

Other deliberate decisions:

  • Cryptographic OTP — time-limited, single-use, bcrypt-hashed before storage
  • Refresh token rotation — each refresh issues a new token and invalidates the old one
  • Forensic audit logging — every sensitive action (login, OTP verify, token refresh) is logged with timestamp, IP, and outcome
  • Database hygiene — expired OTPs and rotated tokens are cleaned up automatically, not left to accumulate

Stack

Layer Technology
Backend NestJS, Passport.js, Prisma ORM
Database PostgreSQL (Dockerized)
Auth JWT, HttpOnly cookies, cryptographic OTP
Frontend Next.js 15, React, Axios interceptors
Docs Swagger / OpenAPI (Centralized Truth architecture)
DevOps Docker, Docker Compose

Getting started

Prerequisites: Node.js 18+, PostgreSQL, Docker

git clone https://github.com/aarogyaojha/AuthProject.git
cd AuthProject

Backend:

cd backend
npm install
cp .env.example .env        # configure your Postgres connection
npx prisma migrate dev
npm run start:dev

Frontend:

cd ../frontend
npm install
cp .env.example .env.local
npm run dev

API docs available at http://localhost:3000/api once the backend is running.


Architecture

AuthProject/
├── backend/          # NestJS — auth logic, OTP, token rotation, audit logs
│   ├── src/
│   │   ├── auth/     # signup, login, OTP verify, refresh, logout
│   │   ├── common/   # constants (Centralized Truth), guards, interceptors
│   │   └── prisma/   # schema, migrations, cleanup jobs
│   └── ...
└── frontend/         # Next.js 15 — multi-step onboarding, auth context, Axios interceptors

License

MIT © Aarogya Ojha