Skip to content

Commit e7a5207

Browse files
feat: introduce @auth/pouchdb-adapter (#7805)
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/pouchdb-adapter": "0.0.0", + "@auth/pouchdb-adapter": "0.0.0", ``` And run `npm install`, `yarn install` or `pnpm install` respectively. **Note:** This packages is published as ESM-only This package assumes that `globalThis.crypto` is available. In older Node.js versions, you can polyfill by adding: `globalThis.crypto ??= require("node:crypto").webcrypto`
1 parent 6e4516a commit e7a5207

File tree

9 files changed

+44
-42
lines changed

9 files changed

+44
-42
lines changed

.github/ISSUE_TEMPLATE/3_bug_adapter.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ body:
2828
- "@auth/mikro-orm-adapter"
2929
- "@auth/mongodb-adapter"
3030
- "@auth/neo4j-adapter"
31-
- "@next-auth/pouchdb-adapter"
31+
- "@auth/pouchdb-adapter"
3232
- "@auth/prisma-adapter"
3333
- "@next-auth/sequelize-adapter"
3434
- "@next-auth/supabase-adapter"

.github/issue-labeler.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ neo4j:
2222
- "@auth/neo4j-adapter"
2323

2424
pouchdb:
25-
- "@next-auth/pouchdb-adapter"
25+
- "@auth/pouchdb-adapter"
2626

2727
prisma:
2828
- "@auth/prisma-adapter"

packages/adapter-pouchdb/README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@
88
</a>
99
<h3 align="center"><b>PouchDB Adapter</b> - NextAuth.js / Auth.js</a></h3>
1010
<p align="center" style="align: center;">
11-
<a href="https://npm.im/@next-auth/pouchdb-adapter">
11+
<a href="https://npm.im/@auth/pouchdb-adapter">
1212
<img src="https://img.shields.io/badge/TypeScript-blue?style=flat-square" alt="TypeScript" />
1313
</a>
14-
<a href="https://npm.im/@next-auth/pouchdb-adapter">
15-
<img alt="npm" src="https://img.shields.io/npm/v/@next-auth/pouchdb-adapter?color=green&label=@next-auth/pouchdb-adapter&style=flat-square">
14+
<a href="https://npm.im/@auth/pouchdb-adapter">
15+
<img alt="npm" src="https://img.shields.io/npm/v/@auth/pouchdb-adapter?color=green&label=@auth/pouchdb-adapter&style=flat-square">
1616
</a>
17-
<a href="https://www.npmtrends.com/@next-auth/pouchdb-adapter">
18-
<img src="https://img.shields.io/npm/dm/@next-auth/pouchdb-adapter?label=%20downloads&style=flat-square" alt="Downloads" />
17+
<a href="https://www.npmtrends.com/@auth/pouchdb-adapter">
18+
<img src="https://img.shields.io/npm/dm/@auth/pouchdb-adapter?label=%20downloads&style=flat-square" alt="Downloads" />
1919
</a>
2020
<a href="https://github.com/nextauthjs/next-auth/stargazers">
2121
<img src="https://img.shields.io/github/stars/nextauthjs/next-auth?style=flat-square" alt="Github Stars" />

packages/adapter-pouchdb/package.json

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
2-
"name": "@next-auth/pouchdb-adapter",
3-
"version": "1.0.0",
2+
"name": "@auth/pouchdb-adapter",
3+
"version": "0.0.0",
44
"description": "PouchDB adapter for next-auth.",
55
"homepage": "https://authjs.dev",
66
"repository": "https://github.com/nextauthjs/next-auth",
@@ -38,24 +38,22 @@
3838
"src"
3939
],
4040
"peerDependencies": {
41-
"next-auth": "^4",
4241
"pouchdb": "^8.0.1",
4342
"pouchdb-find": "^8.0.1"
4443
},
4544
"dependencies": {
46-
"ulid": "2.3.0"
45+
"@auth/core": "workspace:*"
4746
},
4847
"devDependencies": {
4948
"@next-auth/adapter-test": "workspace:*",
5049
"@next-auth/tsconfig": "workspace:*",
5150
"@types/pouchdb": "^6.4.0",
5251
"jest": "^27.4.3",
53-
"next-auth": "workspace:*",
5452
"pouchdb": "^8.0.1",
5553
"pouchdb-adapter-memory": "^8.0.1",
5654
"pouchdb-find": "^8.0.1"
5755
},
5856
"jest": {
5957
"preset": "@next-auth/adapter-test/jest"
6058
}
61-
}
59+
}

packages/adapter-pouchdb/src/index.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99
* ## Installation
1010
*
1111
* ```bash npm2yarn2pnpm
12-
* npm install next-auth pouchdb pouchdb-find @next-auth/pouchdb-adapter
12+
* npm install pouchdb pouchdb-find @auth/pouchdb-adapter
1313
* ```
1414
*
15-
* @module @next-auth/pouchdb-adapter
15+
* @module @auth/pouchdb-adapter
1616
*/
1717

1818
import type {
@@ -21,8 +21,7 @@ import type {
2121
AdapterSession,
2222
AdapterUser,
2323
VerificationToken,
24-
} from "next-auth/adapters"
25-
import { ulid } from "ulid"
24+
} from "@auth/core/adapters"
2625

2726
type PrefixConfig = Record<
2827
"user" | "account" | "session" | "verificationToken",
@@ -99,7 +98,7 @@ export interface PouchDBAdapterOptions {
9998
* ```javascript title="pages/api/auth/[...nextauth].js"
10099
* import NextAuth from "next-auth"
101100
* import GoogleProvider from "next-auth/providers/google"
102-
* import { PouchDBAdapter } from "@next-auth/pouchdb-adapter"
101+
* import { PouchDBAdapter } from "@auth/pouchdb-adapter"
103102
* import PouchDB from "pouchdb"
104103
*
105104
* // Setup your PouchDB instance and database
@@ -154,7 +153,7 @@ export function PouchDBAdapter(options: PouchDBAdapterOptions): Adapter {
154153

155154
return {
156155
async createUser(user) {
157-
const doc = { ...user, _id: [userPrefix, ulid()].join("_") }
156+
const doc = { ...user, _id: [userPrefix, crypto.randomUUID()].join("_") }
158157
await pouchdb.put(doc)
159158
return { ...user, id: doc._id }
160159
},
@@ -220,7 +219,10 @@ export function PouchDBAdapter(options: PouchDBAdapterOptions): Adapter {
220219
async deleteUser(id) {},
221220

222221
async linkAccount(account) {
223-
const doc = { ...account, _id: [accountPrefix, ulid()].join("_") }
222+
const doc = {
223+
...account,
224+
_id: [accountPrefix, crypto.randomUUID()].join("_"),
225+
}
224226
await (pouchdb as unknown as PouchDB.Database<AdapterAccount>).put(doc)
225227

226228
return { ...account, id: doc._id }
@@ -245,7 +247,7 @@ export function PouchDBAdapter(options: PouchDBAdapterOptions): Adapter {
245247

246248
async createSession(data) {
247249
const doc = {
248-
_id: [sessionPrefix, ulid()].join("_"),
250+
_id: [sessionPrefix, crypto.randomUUID()].join("_"),
249251
...data,
250252
}
251253
await (pouchdb as unknown as PouchDB.Database<AdapterSession>).put(doc)
@@ -317,7 +319,7 @@ export function PouchDBAdapter(options: PouchDBAdapterOptions): Adapter {
317319

318320
async createVerificationToken(data) {
319321
await (pouchdb as unknown as PouchDB.Database<VerificationToken>).put({
320-
_id: [verificationTokenPrefix, ulid()].join("_"),
322+
_id: [verificationTokenPrefix, crypto.randomUUID()].join("_"),
321323
...data,
322324
})
323325

packages/adapter-pouchdb/tests/index.test.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,14 @@ import {
1010
import PouchDB from "pouchdb"
1111
import find from "pouchdb-find"
1212
import memoryAdapter from "pouchdb-adapter-memory"
13-
import { ulid } from "ulid"
1413
import {
1514
AdapterAccount,
1615
AdapterSession,
1716
AdapterUser,
1817
VerificationToken,
19-
} from "next-auth/adapters"
18+
} from "@auth/core/adapters"
19+
20+
globalThis.crypto ??= require("node:crypto").webcrypto
2021

2122
// pouchdb setup
2223
PouchDB.plugin(memoryAdapter).plugin(find)
@@ -31,7 +32,7 @@ PouchDB.on("destroyed", function () {
3132
const disconnect = async () => {
3233
if (!pouchdbIsDestroyed) await pouchdb.destroy()
3334
}
34-
pouchdb = new PouchDB(ulid(), { adapter: "memory" })
35+
pouchdb = new PouchDB(crypto.randomUUID(), { adapter: "memory" })
3536

3637
// Basic tests
3738
runBasicTests({
Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,25 @@
11
{
2-
"extends": "@next-auth/tsconfig/tsconfig.adapters.json",
2+
"extends": "@next-auth/tsconfig/tsconfig.base.json",
33
"compilerOptions": {
4-
"rootDir": "src",
5-
"allowSyntheticDefaultImports": true,
6-
"outDir": ".",
4+
"allowJs": true,
5+
"baseUrl": ".",
6+
"isolatedModules": true,
77
"target": "ES2020",
88
"module": "ESNext",
99
"moduleResolution": "node",
10+
"outDir": ".",
11+
"rootDir": "src",
1012
"skipDefaultLibCheck": true,
1113
"strictNullChecks": true,
1214
"stripInternal": true,
1315
"declarationMap": true,
1416
"declaration": true
1517
},
16-
"exclude": ["tests", "jest.config.js"]
17-
}
18+
"include": [
19+
"src/**/*"
20+
],
21+
"exclude": [
22+
"*.js",
23+
"*.d.ts",
24+
]
25+
}

pnpm-lock.yaml

Lines changed: 2 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

turbo.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
"@auth/mikro-orm-adapter#build",
6363
"@auth/mongodb-adapter#build",
6464
"@auth/neo4j-adapter#build",
65-
"@next-auth/pouchdb-adapter#build",
65+
"@auth/pouchdb-adapter#build",
6666
"@next-auth/sequelize-adapter#build",
6767
"@next-auth/supabase-adapter#build",
6868
"@auth/typeorm-adapter#build",
@@ -85,7 +85,7 @@
8585
"@auth/mikro-orm-adapter#build",
8686
"@auth/mongodb-adapter#build",
8787
"@auth/neo4j-adapter#build",
88-
"@next-auth/pouchdb-adapter#build",
88+
"@auth/pouchdb-adapter#build",
8989
"@next-auth/sequelize-adapter#build",
9090
"@next-auth/supabase-adapter#build",
9191
"@auth/typeorm-adapter#build",

0 commit comments

Comments
 (0)