From cd92aa0c82acc8b2748713d2622d1ee284adb614 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bal=C3=A1zs=20Orb=C3=A1n?= Date: Tue, 13 Jun 2023 16:28:33 +0200 Subject: [PATCH] feat: introduce `@auth/dynamodb-adapter` (#7793) 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/dynamodb-adapter": "0.0.0", + "@auth/dynamodb-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` --- .github/ISSUE_TEMPLATE/3_bug_adapter.yml | 2 +- .github/issue-labeler.yml | 2 +- packages/adapter-dynamodb/README.md | 10 +++--- packages/adapter-dynamodb/package.json | 44 +++++++++++------------- packages/adapter-dynamodb/src/index.ts | 15 ++++---- packages/adapter-dynamodb/tsconfig.json | 19 +++++++--- pnpm-lock.yaml | 12 ++----- turbo.json | 4 +-- 8 files changed, 53 insertions(+), 55 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/3_bug_adapter.yml b/.github/ISSUE_TEMPLATE/3_bug_adapter.yml index f68c7dbf..3898e6a3 100644 --- a/.github/ISSUE_TEMPLATE/3_bug_adapter.yml +++ b/.github/ISSUE_TEMPLATE/3_bug_adapter.yml @@ -22,7 +22,7 @@ body: options: - "Custom adapter" - "@auth/dgraph-adapter" - - "@next-auth/dynamodb-adapter" + - "@auth/dynamodb-adapter" - "@next-auth/fauna-adapter" - "@next-auth/firebase-adapter" - "@next-auth/mikro-orm-adapter" diff --git a/.github/issue-labeler.yml b/.github/issue-labeler.yml index 369f49e5..d926e5b0 100644 --- a/.github/issue-labeler.yml +++ b/.github/issue-labeler.yml @@ -4,7 +4,7 @@ dgraph: - "@auth/dgraph-adapter" dynamodb: - - "@next-auth/dynamodb-adapter" + - "@auth/dynamodb-adapter" fauna: - "@next-auth/fauna-adapter" diff --git a/packages/adapter-dynamodb/README.md b/packages/adapter-dynamodb/README.md index b7025a8c..99b1fb26 100644 --- a/packages/adapter-dynamodb/README.md +++ b/packages/adapter-dynamodb/README.md @@ -8,14 +8,14 @@

DynamoDB Adapter - NextAuth.js / Auth.js

- + TypeScript - - npm + + npm - - Downloads + + Downloads Github Stars diff --git a/packages/adapter-dynamodb/package.json b/packages/adapter-dynamodb/package.json index bbc6c2d7..0725e327 100644 --- a/packages/adapter-dynamodb/package.json +++ b/packages/adapter-dynamodb/package.json @@ -1,7 +1,7 @@ { - "name": "@next-auth/dynamodb-adapter", + "name": "@auth/dynamodb-adapter", "repository": "https://github.com/nextauthjs/next-auth", - "version": "3.0.2", + "version": "0.0.0", "description": "AWS DynamoDB adapter for next-auth.", "keywords": [ "next-auth", @@ -9,18 +9,10 @@ "oauth", "dynamodb" ], - "type": "module", - "types": "./index.d.ts", "homepage": "https://authjs.dev", "bugs": { "url": "https://github.com/nextauthjs/next-auth/issues" }, - "exports": { - ".": { - "types": "./index.d.ts", - "import": "./index.js" - } - }, "private": false, "publishConfig": { "access": "public" @@ -32,19 +24,27 @@ "clean": "rm -rf index.*", "build": "pnpm clean && tsc" }, + "author": "Pol Marnette", + "contributors": [ + "Balázs Orbán " + ], + "license": "ISC", + "type": "module", + "types": "./index.d.ts", "files": [ - "README.md", - "index.js", - "index.d.ts", - "index.d.ts.map", + "*.js", + "*.d.ts*", "src" ], - "author": "Pol Marnette", - "license": "ISC", + "exports": { + ".": { + "types": "./index.d.ts", + "import": "./index.js" + } + }, "peerDependencies": { "@aws-sdk/client-dynamodb": "^3.36.1", - "@aws-sdk/lib-dynamodb": "^3.36.1", - "next-auth": "^4" + "@aws-sdk/lib-dynamodb": "^3.36.1" }, "devDependencies": { "@aws-sdk/client-dynamodb": "^3.36.1", @@ -52,11 +52,9 @@ "@next-auth/adapter-test": "workspace:*", "@next-auth/tsconfig": "workspace:*", "@shelf/jest-dynamodb": "^2.1.0", - "@types/uuid": "^9.0.0", - "jest": "^27.4.3", - "next-auth": "workspace:*" + "jest": "^27.4.3" }, "dependencies": { - "uuid": "^9.0.0" + "@auth/core": "workspace:*" } -} \ No newline at end of file +} diff --git a/packages/adapter-dynamodb/src/index.ts b/packages/adapter-dynamodb/src/index.ts index 2c6467c4..1c5b4f32 100644 --- a/packages/adapter-dynamodb/src/index.ts +++ b/packages/adapter-dynamodb/src/index.ts @@ -9,12 +9,11 @@ * ## Installation * * ```bash npm2yarn2pnpm - * npm install next-auth @next-auth/dynamodb-adapter + * npm install next-auth @auth/dynamodb-adapter * ``` * - * @module @next-auth/dynamodb-adapter + * @module @auth/dynamodb-adapter */ -import { v4 as uuid } from "uuid" import type { BatchWriteCommandInput, @@ -26,7 +25,7 @@ import type { AdapterAccount, AdapterUser, VerificationToken, -} from "next-auth/adapters" +} from "@auth/core/adapters" export interface DynamoDBAdapterOptions { tableName?: string @@ -53,7 +52,7 @@ export interface DynamoDBAdapterOptions { * import { DynamoDBDocument } from "@aws-sdk/lib-dynamodb" * import NextAuth from "next-auth"; * import Providers from "next-auth/providers"; - * import { DynamoDBAdapter } from "@next-auth/dynamodb-adapter" + * import { DynamoDBAdapter } from "@auth/dynamodb-adapter" * * const config: DynamoDBClientConfig = { * credentials: { @@ -187,7 +186,7 @@ export function DynamoDBAdapter( async createUser(data) { const user: AdapterUser = { ...(data as any), - id: uuid(), + id: crypto.randomUUID(), } await client.put({ @@ -312,7 +311,7 @@ export function DynamoDBAdapter( async linkAccount(data) { const item = { ...data, - id: uuid(), + id: crypto.randomUUID(), [pk]: `USER#${data.userId}`, [sk]: `ACCOUNT#${data.provider}#${data.providerAccountId}`, [GSI1PK]: `ACCOUNT#${data.provider}`, @@ -376,7 +375,7 @@ export function DynamoDBAdapter( }, async createSession(data) { const session = { - id: uuid(), + id: crypto.randomUUID(), ...data, } await client.put({ diff --git a/packages/adapter-dynamodb/tsconfig.json b/packages/adapter-dynamodb/tsconfig.json index 61e9b26f..726c2dc1 100644 --- a/packages/adapter-dynamodb/tsconfig.json +++ b/packages/adapter-dynamodb/tsconfig.json @@ -1,16 +1,25 @@ { - "extends": "@next-auth/tsconfig/tsconfig.adapters.json", + "extends": "@next-auth/tsconfig/tsconfig.base.json", "compilerOptions": { - "rootDir": "src", - "outDir": ".", + "allowJs": true, + "baseUrl": ".", + "isolatedModules": true, "target": "ES2020", "module": "ESNext", "moduleResolution": "node", + "outDir": ".", + "rootDir": "src", "skipDefaultLibCheck": true, "strictNullChecks": true, "stripInternal": true, "declarationMap": true, "declaration": true }, - "exclude": ["tests", "dist", "jest.config.js", "jest-dynamodb-config.js"] -} + "include": [ + "src/**/*" + ], + "exclude": [ + "*.js", + "*.d.ts", + ] +} \ No newline at end of file diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 7566555d..049887c9 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -276,26 +276,22 @@ importers: packages/adapter-dynamodb: specifiers: + '@auth/core': workspace:* '@aws-sdk/client-dynamodb': ^3.36.1 '@aws-sdk/lib-dynamodb': ^3.36.1 '@next-auth/adapter-test': workspace:* '@next-auth/tsconfig': workspace:* '@shelf/jest-dynamodb': ^2.1.0 - '@types/uuid': ^9.0.0 jest: ^27.4.3 - next-auth: workspace:* - uuid: ^9.0.0 dependencies: - uuid: 9.0.0 + '@auth/core': link:../core devDependencies: '@aws-sdk/client-dynamodb': 3.113.0 '@aws-sdk/lib-dynamodb': 3.113.0_eb2z3hhrjl3qvyc6ecmpo2nhva '@next-auth/adapter-test': link:../adapter-test '@next-auth/tsconfig': link:../tsconfig '@shelf/jest-dynamodb': 2.2.4_qsruu6yolbxs4rh6ixjhkibvwu - '@types/uuid': 9.0.0 jest: 27.5.1 - next-auth: link:../next-auth packages/adapter-fauna: specifiers: @@ -11446,10 +11442,6 @@ packages: resolution: {integrity: sha512-c/I8ZRb51j+pYGAu5CrFMRxqZ2ke4y2grEBO5AUjgSkSk+qT2Ea+OdWElz/OiMf5MNpn2b17kuVBwZLQJXzihw==} dev: true - /@types/uuid/9.0.0: - resolution: {integrity: sha512-kr90f+ERiQtKWMz5rP32ltJ/BtULDI5RVO0uavn1HQUOwjx0R1h0rnDYNL0CepF1zL5bSY6FISAfd9tOdDhU5Q==} - dev: true - /@types/validator/13.7.3: resolution: {integrity: sha512-DNviAE5OUcZ5s+XEQHRhERLg8fOp8gSgvyJ4aaFASx5wwaObm+PBwTIMXiOFm1QrSee5oYwEAYb7LMzX2O88gA==} dev: true diff --git a/turbo.json b/turbo.json index 49c75f05..65c19671 100644 --- a/turbo.json +++ b/turbo.json @@ -56,7 +56,7 @@ "@auth/prisma-adapter#build", "@auth/sveltekit#build", "@auth/dgraph-adapter#build", - "@next-auth/dynamodb-adapter#build", + "@auth/dynamodb-adapter#build", "@next-auth/fauna-adapter#build", "@next-auth/firebase-adapter#build", "@next-auth/mikro-orm-adapter#build", @@ -79,7 +79,7 @@ "@auth/prisma-adapter#build", "@auth/sveltekit#build", "@auth/dgraph-adapter#build", - "@next-auth/dynamodb-adapter#build", + "@auth/dynamodb-adapter#build", "@next-auth/fauna-adapter#build", "@next-auth/firebase-adapter#build", "@next-auth/mikro-orm-adapter#build",