Database overview

Three production-ready database backends - MongoDB, Supabase, and Firebase. Same auth logic, same security model, different data access layer.

The variant system

NextForge ships with three database implementations in _variants/. The auth logic, OTP flow, validation, sanitization, and rate limiting are identical across all variants - only the data access layer differs.

  • _variants/mongodb/ - Mongoose models, pre-save hooks, TTL index
  • _variants/supabase/ - Supabase JS client, SQL schema, parameterized queries
  • _variants/firebase/ - firebase-admin, Firestore collections, server-side only

What setup.mjs does

  1. Presents the interactive CLI - choose 1, 2, or 3
  2. Copies the chosen variant's files to their correct locations in lib/db/
  3. Patches package.json to remove the other two variants' dependencies
  4. Generates .env.local.example with only the env vars for your chosen database
  5. Deletes _variants/ and setup.mjs itself

The result is a standard Next.js project with no trace of the scaffold. Only your chosen database's dependencies are installed.

Identical contracts

Regardless of which database you choose, actions/auth.ts and actions/email.ts import the same function signatures:

// These imports work identically across all three variants:
import { connectDB } from '@/lib/db/client'
import { createUser, findUserByEmail, updateUserVerified,
         updateUserPassword } from '@/lib/db/user'
import { createOTP, findValidOTP, markOTPUsed } from '@/lib/db/otp'

Verification path

Use the shared verification checklist after setup, then drop into the variant-specific guide if anything fails.

Choosing a database

A simple guide:

  • MongoDB - best if you're comfortable with document databases, using MongoDB Atlas free tier, or need flexible schema evolution
  • Supabase - best if you prefer SQL, want a managed Postgres with a dashboard, or plan to use Supabase's other features (storage, realtime)
  • Firebase - best if you're already in the Google Cloud ecosystem or want Firestore's real-time capabilities alongside NextForge's auth