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
- Presents the interactive CLI - choose 1, 2, or 3
- Copies the chosen variant's files to their correct locations in lib/db/
- Patches package.json to remove the other two variants' dependencies
- Generates .env.local.example with only the env vars for your chosen database
- 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'The function names above are conceptual - see each variant's docs page for the actual implementation signatures.
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
All three are available on generous free tiers. The security model and auth behavior are identical - you can switch variants by re-cloning and running setup.mjs again.