This repository contains a full-stack User Authentication System built with Next.js (Frontend) and NestJS (Backend).
The entire system, including the PostgreSQL database, is orchestrated using Docker Compose.
- Docker and Docker Compose installed.
Run the following command in the root directory:
docker-compose up --build- Frontend: http://localhost:3000
- Backend API: http://localhost:3001
- Framework: NestJS 11 (Modular Architecture).
- Database: PostgreSQL 15 with Prisma ORM 6 (using
@prisma/adapter-pg). - User Roles: Supports
ADMINandUSERroles. - Security:
- Password hashing with
bcrypt. - JWT Authentication using
Passport&@nestjs/jwt. - Global
ValidationPipe.
- Password hashing with
- Branch renamed: Development moved to
feature/auth-roles. - Admin registration: Fixed bug where
isAdminfield was ignored by the backend. - Role assignment: Users can now register as
ADMINusing the "Admin Mode" toggle. - Dashboard integration: The user's role is now visible in the secure dashboard.
- Framework: Next.js 16 (React 19, App Router).
- Styling: Tailwind CSS v4 (
@tailwindcss/postcss). - UI Components: Custom components, toast notifications with
sonner. - State Management: React Hooks & Local Storage.
- Authentication Flow:
- JWT storage in
localStorage. - Client-side route protection using HOC/Hooks (
AuthGuard). - Automatic redirect to
/loginfor unauthenticated access to protected routes.
- JWT storage in
If you prefer to run the components separately without Docker for the host application:
You can start only the database using Docker:
docker-compose up -d postgrescd backend
npm install
# Configure .env (copy from .env.example)
npx prisma migrate dev
npm run start:devcd frontend
npm install
# Configure .env.local (copy from .env.local.example)
npm run devCreate .env files in both backend/ and frontend/ (or .env.local for frontend) with the following keys:
Backend (backend/.env):
DATABASE_URL="postgresql://postgres:postgres@localhost:5433/postgres?schema=public"
JWT_SECRET="super-secret-key"
JWT_EXPIRES_IN="1h"Frontend (frontend/.env.local):
NEXT_PUBLIC_API_URL="http://localhost:3001"If you see missing dependency errors in the backend logs, the Docker container might be stale. Rebuild it:
docker-compose up -d --build backend- Register Page
- Login Page
- Protected Dashboard
- Backend API with JWT
- Password Hashing (bcrypt)
- Form Validations
- Dockerization (Full Stack)
- Documentation (README)