Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/brendon1555/authjs-mongoose-adapter
An adapter for Auth.js/NextAuth.js to allow you to connect to a MongoDB using Mongoose.
https://github.com/brendon1555/authjs-mongoose-adapter
authjs mongodb mongoose next-auth nextjs
Last synced: 3 months ago
JSON representation
An adapter for Auth.js/NextAuth.js to allow you to connect to a MongoDB using Mongoose.
- Host: GitHub
- URL: https://github.com/brendon1555/authjs-mongoose-adapter
- Owner: brendon1555
- License: isc
- Created: 2024-05-13T01:29:09.000Z (8 months ago)
- Default Branch: main
- Last Pushed: 2024-05-14T04:43:15.000Z (8 months ago)
- Last Synced: 2024-09-19T13:38:15.221Z (3 months ago)
- Topics: authjs, mongodb, mongoose, next-auth, nextjs
- Language: TypeScript
- Homepage:
- Size: 103 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Mongoose Adapter - NextAuth.js / Auth.js
---
> [!WARNING]
>
> This adapter cannot support Next.js middleware with `next-auth` until Mongoose supports the Next.js Edge Runtime. _Or_, Next.js adds Node.js `net` API support to middlewares. You _CAN_ still generally use it with Next.js however.
> See: [Mongoose docs](https://mongoosejs.com/docs/nextjs.html#:~:text=Mongoose%20does%20not%20currently%20support%20Next.js%20Edge%20Runtime.)## Getting Started
1. Install Auth.js (`@auth/express`, `@auth/sveltekit`, `next-auth`, etc.), `mongoose` and `@brendon1555/authjs-mongoose-adapter`:
```bash
npm install @brendon1555/authjs-mongoose-adapter mongoose @auth/express
```2. Add a MongoDB connection string to your environment variables:
```env
MONGODB_URI=mongodb://localhost:27017/my-database
```3. Add this adapter to your auth config:
1. Express
```js
import { ExpressAuth } from "@auth/express";
import { MongooseAdapter } from "@brendon1555/authjs-mongoose-adapter";const app = express();
app.use(
"/auth/*",
ExpressAuth({
adapter: MongooseAdapter(process.env.MONGODB_URI),
...
})
);
```2. SvelteKit
```js
import { SvelteKitAuth } from "@auth/sveltekit";
import { MongooseAdapter } from "@brendon1555/authjs-mongoose-adapter"export const { handle, signIn, signOut } = SvelteKitAuth({
adapter: MongoDBAdapter(process.env.MONGODB_URI),
...
});
```3. Next.js (Middleware not supported yet)
```js
import NextAuth from "next-auth"
import { MongooseAdapter } from "@brendon1555/authjs-mongoose-adapter"export default NextAuth({
adapter: MongooseAdapter(process.env.MONGODB_URI),
...
})
```## License
ISC