Skip to content

Commit

Permalink
feat: introduce @auth/prisma-adapter (#7703)
Browse files Browse the repository at this point in the history
BREAKING CHANGE:
If you are coming from the previous adapter, change your `package.json`:

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

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

**Note:** This packages is published as ESM-only.
  • Loading branch information
balazsorban44 committed Jun 1, 2023
1 parent cda07c2 commit 2ecf52c
Show file tree
Hide file tree
Showing 15 changed files with 119 additions and 55 deletions.
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/3_bug_adapter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ body:
- "@next-auth/mongodb-adapter"
- "@next-auth/neo4j-adapter"
- "@next-auth/pouchdb-adapter"
- "@next-auth/prisma-adapter"
- "@auth/prisma-adapter"
- "@next-auth/sequelize-adapter"
- "@next-auth/supabase-adapter"
- "@next-auth/typeorm-legacy-adapter"
Expand Down
2 changes: 1 addition & 1 deletion .github/issue-labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pouchdb:
- "@next-auth/pouchdb-adapter"

prisma:
- "@next-auth/prisma-adapter"
- "@auth/prisma-adapter"

sequelize:
- "@next-auth/sequelize-adapter"
Expand Down
2 changes: 1 addition & 1 deletion apps/dev/nextjs-v4/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"license": "ISC",
"dependencies": {
"@next-auth/fauna-adapter": "workspace:*",
"@next-auth/prisma-adapter": "workspace:*",
"@auth/prisma-adapter": "workspace:*",
"@next-auth/supabase-adapter": "workspace:*",
"@next-auth/typeorm-legacy-adapter": "workspace:*",
"@prisma/client": "^3",
Expand Down
2 changes: 1 addition & 1 deletion apps/dev/nextjs-v4/pages/api/auth-old/[...nextauth].ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import WorkOS from "next-auth/providers/workos"

// // Prisma
// import { PrismaClient } from "@prisma/client"
// import { PrismaAdapter } from "@next-auth/prisma-adapter"
// import { PrismaAdapter } from "@auth/prisma-adapter"
// const client = globalThis.prisma || new PrismaClient()
// if (process.env.NODE_ENV !== "production") globalThis.prisma = client
// const adapter = PrismaAdapter(client)
Expand Down
2 changes: 1 addition & 1 deletion apps/dev/nextjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"dependencies": {
"@auth/core": "workspace:*",
"@next-auth/fauna-adapter": "workspace:*",
"@next-auth/prisma-adapter": "workspace:*",
"@auth/prisma-adapter": "workspace:*",
"@next-auth/supabase-adapter": "workspace:*",
"@next-auth/typeorm-legacy-adapter": "workspace:*",
"@prisma/client": "^3",
Expand Down
2 changes: 1 addition & 1 deletion apps/dev/nextjs/pages/api/auth/[...nextauth].ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import WorkOS from "@auth/core/providers/workos"

// // Prisma
// import { PrismaClient } from "@prisma/client"
// import { PrismaAdapter } from "@next-auth/prisma-adapter"
// import { PrismaAdapter } from "@auth/prisma-adapter"
// const client = globalThis.prisma || new PrismaClient()
// if (process.env.NODE_ENV !== "production") globalThis.prisma = client
// const adapter = PrismaAdapter(client)
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/guides/basics/refresh-token-rotation.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ Using the database strategy is very similar, but instead of preserving the `acce
import { Auth } from "@auth/core"
import { type TokenSet } from "@auth/core/types"
import Google from "@auth/core/providers/google"
import { PrismaAdapter } from "@next-auth/prisma-adapter"
import { PrismaAdapter } from "@auth/prisma-adapter"
import { PrismaClient } from "@prisma/client"

const prisma = new PrismaClient()
Expand Down
10 changes: 5 additions & 5 deletions packages/adapter-prisma/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
</a>
<h3 align="center"><b>Prisma Adapter</b> - NextAuth.js / Auth.js</a></h3>
<p align="center" style="align: center;">
<a href="https://npm.im/@next-auth/prisma-adapter">
<a href="https://npm.im/@auth/prisma-adapter">
<img src="https://img.shields.io/badge/TypeScript-blue?style=flat-square" alt="TypeScript" />
</a>
<a href="https://npm.im/@next-auth/prisma-adapter">
<img alt="npm" src="https://img.shields.io/npm/v/@next-auth/prisma-adapter?color=green&label=@next-auth/prisma-adapter&style=flat-square">
<a href="https://npm.im/@auth/prisma-adapter">
<img alt="npm" src="https://img.shields.io/npm/v/@auth/prisma-adapter?color=green&label=@auth/prisma-adapter&style=flat-square">
</a>
<a href="https://www.npmtrends.com/@next-auth/prisma-adapter">
<img src="https://img.shields.io/npm/dm/@next-auth/prisma-adapter?label=%20downloads&style=flat-square" alt="Downloads" />
<a href="https://www.npmtrends.com/@auth/prisma-adapter">
<img src="https://img.shields.io/npm/dm/@auth/prisma-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" />
Expand Down
42 changes: 27 additions & 15 deletions packages/adapter-prisma/package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,29 @@
{
"name": "@next-auth/prisma-adapter",
"version": "1.0.7",
"description": "Prisma adapter for next-auth.",
"homepage": "https://authjs.dev",
"name": "@auth/prisma-adapter",
"version": "0.0.0",
"description": "Prisma adapter for Auth.js",
"homepage": "https://authjs.dev/reference/adapter/prisma",
"repository": "https://github.com/nextauthjs/next-auth",
"bugs": {
"url": "https://github.com/nextauthjs/next-auth/issues"
},
"author": "William Luke",
"main": "dist/index.js",
"contributors": [
"Balázs Orbán <info@balazsorban.com>"
],
"type": "module",
"types": "./index.d.ts",
"files": [
"*.js",
"*.d.ts*",
"src"
],
"exports": {
".": {
"types": "./index.d.ts",
"import": "./index.js"
}
},
"license": "ISC",
"keywords": [
"next-auth",
Expand All @@ -32,24 +47,21 @@
"dev": "prisma generate && tsc -w",
"studio": "prisma studio"
},
"files": [
"README.md",
"dist"
],
"dependencies": {
"@auth/core": "workspace:*"
},
"peerDependencies": {
"@prisma/client": ">=2.26.0 || >=3",
"next-auth": "^4"
"@prisma/client": ">=2.26.0 || >=3 || >=4"
},
"devDependencies": {
"@next-auth/adapter-test": "workspace:*",
"@next-auth/tsconfig": "workspace:*",
"@prisma/client": "^3.10.0",
"@prisma/client": "^4.15.0",
"jest": "^27.4.3",
"mongodb": "^4.4.0",
"next-auth": "workspace:*",
"prisma": "^3.10.0"
"prisma": "^4.15.0"
},
"jest": {
"preset": "@next-auth/adapter-test/jest"
}
}
}
8 changes: 4 additions & 4 deletions packages/adapter-prisma/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
* ## Installation
*
* ```bash npm2yarn2pnpm
* npm install next-auth @prisma/client @next-auth/prisma-adapter
* npm install @prisma/client @auth/prisma-adapter
* npm install prisma --save-dev
* ```
*
* @module @next-auth/prisma-adapter
* @module @auth/prisma-adapter
*/
import type { PrismaClient, Prisma } from "@prisma/client"
import type { Adapter, AdapterAccount } from "next-auth/adapters"
import type { Adapter, AdapterAccount } from "@auth/core/adapters"

/**
* ## Setup
Expand All @@ -26,7 +26,7 @@ import type { Adapter, AdapterAccount } from "next-auth/adapters"
* ```js title="pages/api/auth/[...nextauth].js"
* import NextAuth from "next-auth"
* import GoogleProvider from "next-auth/providers/google"
* import { PrismaAdapter } from "@next-auth/prisma-adapter"
* import { PrismaAdapter } from "@auth/prisma-adapter"
* import { PrismaClient } from "@prisma/client"
*
* const prisma = new PrismaClient()
Expand Down
26 changes: 21 additions & 5 deletions packages/adapter-prisma/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,9 +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
},
"include": ["."],
"exclude": ["tests", "dist", "jest.config.js"]
}
"include": [
"src/**/*"
],
"exclude": [
"*.js",
"*.d.ts",
]
}
7 changes: 4 additions & 3 deletions packages/adapter-test/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Adapter } from "next-auth/adapters"
import type { Adapter } from "@auth/core/adapters"
import { createHash, randomUUID } from "crypto"

const requiredMethods = [
Expand Down Expand Up @@ -58,7 +58,8 @@ export async function runBasicTests(options: TestOptions) {
await options.db.connect?.()
})

const { adapter, db, skipTests } = options
const { adapter: _adapter, db, skipTests } = options
const adapter = _adapter as Required<Adapter>

afterAll(async () => {
// @ts-expect-error This is only used for the TypeORM adapter
Expand Down Expand Up @@ -88,7 +89,7 @@ export async function runBasicTests(options: TestOptions) {
providerAccountId: randomUUID(),
type: "oauth",
access_token: randomUUID(),
expires_at: ONE_MONTH,
expires_at: ONE_MONTH / 1000,
id_token: randomUUID(),
refresh_token: randomUUID(),
token_type: "bearer",
Expand Down
2 changes: 1 addition & 1 deletion packages/adapter-test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
"license": "ISC",
"private": true,
"devDependencies": {
"@auth/core": "workspace:*",
"@babel/cli": "^7.14.3",
"@babel/plugin-transform-runtime": "^7.14.3",
"@babel/preset-env": "^7.14.2",
"@types/jest": "^26.0.23",
"@types/nodemailer": "^6.4.4",
"jest": "^27.0.3",
"next-auth": "workspace:*",
"ts-jest": "^27.0.3",
"typescript": "^4.2.4"
}
Expand Down
Loading

0 comments on commit 2ecf52c

Please sign in to comment.