feat: introduce @auth/mongodb-adapter (#7790)

Database adapters are not dependent on Next.js features, so it makes sense to republish them under the `@auth/*` scope.

This PR is part of a series to convert adapters, using `@auth/core` for types.

BREAKING CHANGE:
If you are coming from the previous adapter, change your `package.json`:

```diff
-  "@next-auth/mongodb-adapter": "0.0.0",
+  "@auth/mongodb-adapter": "0.0.0",
```

And run `npm install`, `yarn install` or `pnpm install` respectively.

**Note:** This packages is published as ESM-only
This commit is contained in:
Balázs Orbán
2023-06-13 13:41:12 +02:00
committed by GitHub
parent d6abccd9a0
commit 87298a0150
9 changed files with 60 additions and 33 deletions

View File

@@ -26,7 +26,7 @@ body:
- "@next-auth/fauna-adapter"
- "@next-auth/firebase-adapter"
- "@next-auth/mikro-orm-adapter"
- "@next-auth/mongodb-adapter"
- "@auth/mongodb-adapter"
- "@next-auth/neo4j-adapter"
- "@next-auth/pouchdb-adapter"
- "@auth/prisma-adapter"

View File

@@ -16,7 +16,7 @@ mikro-orm:
- "@next-auth/mikro-orm-adapter"
mongodb:
- "@next-auth/mongodb-adapter"
- "@auth/mongodb-adapter"
neo4j:
- "@next-auth/neo4j-adapter"

View File

@@ -96,7 +96,7 @@ For this tutorial, we're going to use the **MongoDB** adapter, but any of the ot
First, let's start by installing the adapter package:
```bash npm2yarn2pnpm
npm install -D @next-auth/mongodb-adapter mongodb
npm install -D @auth/mongodb-adapter mongodb
```
and create a simple MongoDB client:
@@ -142,7 +142,7 @@ And now let's reference this new adapter from our Auth.js configuration file:
```diff title="pages/api/auth/[...nextauth].ts"
import NextAuth from "next-auth"
import EmailProvider from "next-auth/providers/email"
+ import { MongoDBAdapter } from "@next-auth/mongodb-adapter"
+ import { MongoDBAdapter } from "@auth/mongodb-adapter"
+ import clientPromise from "../../../lib/mongodb/client"
export default NextAuth({

View File

@@ -8,14 +8,14 @@
</a>
<h3 align="center"><b>MongoDB Adapter</b> - NextAuth.js / Auth.js</a></h3>
<p align="center" style="align: center;">
<a href="https://npm.im/@next-auth/mongodb-adapter">
<a href="https://npm.im/@auth/mongodb-adapter">
<img src="https://img.shields.io/badge/TypeScript-blue?style=flat-square" alt="TypeScript" />
</a>
<a href="https://npm.im/@next-auth/mongodb-adapter">
<img alt="npm" src="https://img.shields.io/npm/v/@next-auth/mongodb-adapter?color=green&label=@next-auth/mongodb-adapter&style=flat-square">
<a href="https://npm.im/@auth/mongodb-adapter">
<img alt="npm" src="https://img.shields.io/npm/v/@auth/mongodb-adapter?color=green&label=@auth/mongodb-adapter&style=flat-square">
</a>
<a href="https://www.npmtrends.com/@next-auth/mongodb-adapter">
<img src="https://img.shields.io/npm/dm/@next-auth/mongodb-adapter?label=%20downloads&style=flat-square" alt="Downloads" />
<a href="https://www.npmtrends.com/@auth/mongodb-adapter">
<img src="https://img.shields.io/npm/dm/@auth/mongodb-adapter?label=%20downloads&style=flat-square" alt="Downloads" />
</a>
<a href="https://github.com/nextauthjs/next-auth/stargazers">
<img src="https://img.shields.io/github/stars/nextauthjs/next-auth?style=flat-square" alt="Github Stars" />

View File

@@ -1,14 +1,26 @@
{
"name": "@next-auth/mongodb-adapter",
"name": "@auth/mongodb-adapter",
"version": "1.1.3",
"description": "mongoDB adapter for next-auth.",
"description": "MongoDB adapter for Auth.js",
"homepage": "https://authjs.dev",
"repository": "https://github.com/nextauthjs/next-auth",
"bugs": {
"url": "https://github.com/nextauthjs/next-auth/issues"
},
"author": "Balázs Orbán <info@balazsorban.com>",
"main": "dist/index.js",
"type": "module",
"types": "./index.d.ts",
"files": [
"*.js",
"*.d.ts*",
"src"
],
"exports": {
".": {
"types": "./index.d.ts",
"import": "./index.js"
}
},
"license": "ISC",
"keywords": [
"next-auth",
@@ -26,22 +38,19 @@
"test:watch": "./tests/test.sh -w",
"build": "tsc"
},
"files": [
"README.md",
"dist"
],
"dependencies": {
"@auth/core": "workspace:*"
},
"peerDependencies": {
"mongodb": "^5 || ^4",
"next-auth": "^4"
"mongodb": "^5 || ^4"
},
"devDependencies": {
"@next-auth/adapter-test": "workspace:*",
"@next-auth/tsconfig": "workspace:*",
"jest": "^27.4.3",
"mongodb": "^5.1.0",
"next-auth": "workspace:*"
"mongodb": "^5.1.0"
},
"jest": {
"preset": "@next-auth/adapter-test/jest"
}
}
}

View File

@@ -9,10 +9,10 @@
* ## Installation
*
* ```bash npm2yarn2pnpm
* npm install next-auth @next-auth/mongodb-adapter mongodb
* npm install @auth/mongodb-adapter mongodb
* ```
*
* @module @next-auth/mongodb-adapter
* @module @auth/mongodb-adapter
*/
import { ObjectId } from "mongodb"
@@ -22,7 +22,7 @@ import type {
AdapterAccount,
AdapterSession,
VerificationToken,
} from "next-auth/adapters"
} from "@auth/core/adapters"
import type { MongoClient } from "mongodb"
/** This is the interface of the MongoDB adapter options. */
@@ -132,7 +132,7 @@ export function _id(hex?: string) {
*
* ```js
* import NextAuth from "next-auth"
* import { MongoDBAdapter } from "@next-auth/mongodb-adapter"
* import { MongoDBAdapter } from "@auth/mongodb-adapter"
* import clientPromise from "../../../lib/mongodb"
*
* // For more information on each option (and a full list of options) go to

View File

@@ -1,8 +1,25 @@
{
"extends": "@next-auth/tsconfig/tsconfig.adapters.json",
"extends": "@next-auth/tsconfig/tsconfig.base.json",
"compilerOptions": {
"allowJs": true,
"baseUrl": ".",
"isolatedModules": true,
"target": "ES2020",
"module": "ESNext",
"moduleResolution": "node",
"outDir": ".",
"rootDir": "src",
"outDir": "dist"
"skipDefaultLibCheck": true,
"strictNullChecks": true,
"stripInternal": true,
"declarationMap": true,
"declaration": true
},
"exclude": ["tests", "dist", "jest.config.js"]
}
"include": [
"src/**/*"
],
"exclude": [
"*.js",
"*.d.ts",
]
}

5
pnpm-lock.yaml generated
View File

@@ -352,17 +352,18 @@ importers:
packages/adapter-mongodb:
specifiers:
'@auth/core': workspace:*
'@next-auth/adapter-test': workspace:*
'@next-auth/tsconfig': workspace:*
jest: ^27.4.3
mongodb: ^5.1.0
next-auth: workspace:*
dependencies:
'@auth/core': link:../core
devDependencies:
'@next-auth/adapter-test': link:../adapter-test
'@next-auth/tsconfig': link:../tsconfig
jest: 27.5.1
mongodb: 5.1.0
next-auth: link:../next-auth
packages/adapter-neo4j:
specifiers:

View File

@@ -60,7 +60,7 @@
"@next-auth/fauna-adapter#build",
"@next-auth/firebase-adapter#build",
"@next-auth/mikro-orm-adapter#build",
"@next-auth/mongodb-adapter#build",
"@auth/mongodb-adapter#build",
"@next-auth/neo4j-adapter#build",
"@next-auth/pouchdb-adapter#build",
"@next-auth/sequelize-adapter#build",
@@ -83,7 +83,7 @@
"@next-auth/fauna-adapter#build",
"@next-auth/firebase-adapter#build",
"@next-auth/mikro-orm-adapter#build",
"@next-auth/mongodb-adapter#build",
"@auth/mongodb-adapter#build",
"@next-auth/neo4j-adapter#build",
"@next-auth/pouchdb-adapter#build",
"@next-auth/sequelize-adapter#build",