The absolute bare minimum to get auth working. Just register + login.
my-app/
├── src/
│ ├── auth/ ← Copy ModularAuth-Kit's src/auth/ here
│ └── server.ts ← Single file setup
├── .env
└── package.json
// In your existing server.ts — add these 3 lines
import { createConfig, createAuthModule } from './auth/index.js';
const config = createConfig({ session: { secure: false } });
app.use('/auth', createAuthModule(config));Add one env var to your existing .env:
SESSION_SECRET=any-random-string-at-least-32-chars-long💡 If you already have
mongoose.connect(), that's all you need. NoMONGODB_URIorconnectDatabase().
If starting fresh, you also need MongoDB and Express:
// src/server.ts
import 'dotenv/config';
import express from 'express';
import mongoose from 'mongoose';
import { createConfig, createAuthModule } from './auth/index.js';
async function main() {
await mongoose.connect(process.env.MONGODB_URI ?? 'mongodb://localhost:27017/myapp');
const app = express();
app.use(express.json());
const config = createConfig({ session: { secure: false } });
app.use('/auth', createAuthModule(config));
app.get('/', (req, res) => {
res.json({ message: 'Hello! Visit /auth/register to create an account.' });
});
app.listen(3000, () => console.log('http://localhost:3000'));
}
main();# 1. Start
npm run dev
# 2. Register
curl -X POST http://localhost:3000/auth/register \
-H "Content-Type: application/json" \
-d '{"email":"me@test.com","password":"Test1234!"}' \
-c cookies.txt
# 3. Check profile
curl http://localhost:3000/auth/me -b cookies.txt
# 4. Logout
curl -X POST http://localhost:3000/auth/logout -b cookies.txt
# 5. Login
curl -X POST http://localhost:3000/auth/login \
-H "Content-Type: application/json" \
-d '{"identifier":"me@test.com","password":"Test1234!"}' \
-c cookies.txtPOST /auth/register— Register with email + passwordPOST /auth/login— LoginPOST /auth/logout— LogoutPOST /auth/logout-all— Logout all devicesGET /auth/me— Get profilePATCH /auth/me— Update profilePOST /auth/change-password— Change password
That's it. 5 lines of config, 7 endpoints. Add more features as you need them.