@custom-auth/mongoose
v1.0.11
Published
Mongoose database adapter for @custom-auth.
Maintainers
Readme
@custom-auth/mongoose
📦 Ecosystem Packages
- 🔑 Core Engine (@custom-auth/core) — The core framework-agnostic auth engine.
- ⚛️ React SDK (@custom-auth/react) — React hooks and context provider.
- 🌐 Next.js SDK (@custom-auth/nextjs) — Edge-compatible Next.js helpers and middleware.
- 🗄️ Database Adapters:
- ✉️ Email Adapters:
The official Mongoose (MongoDB) adapter for @custom-auth.
Installation
# Install the core engine, the Mongoose adapter, and your chosen email adapter
npm install @custom-auth/core @custom-auth/mongoose <your-email-adapter>Quick Start
import { CustomAuth } from '@custom-auth/core';
import { MongooseAdapter } from '@custom-auth/mongoose';
import mongoose from 'mongoose';
await mongoose.connect(process.env.MONGODB_URI);
export const auth = new CustomAuth({
db: new MongooseAdapter(),
// ...other config
});Extending the Schema
The Mongoose adapter automatically registers the User, Session, and VerificationToken models under the hood. However, you can extend the built-in schemas if you need custom fields:
import mongoose from 'mongoose';
import { MongooseAdapter, UserSchema } from '@custom-auth/mongoose';
// Add custom fields to the user schema
UserSchema.add({ stripeCustomerId: String, plan: { type: String, default: 'free' } });
const UserModel = mongoose.model('User', UserSchema);
export const auth = new CustomAuth({
db: new MongooseAdapter({ UserModel }),
});Documentation
For full documentation, please visit the Main Repository.
