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`
This commit is contained in:
Balázs Orbán
2023-06-13 16:28:33 +02:00
committed by GitHub
parent d414e01181
commit cd92aa0c82
8 changed files with 53 additions and 55 deletions

View File

@@ -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"

View File

@@ -4,7 +4,7 @@ dgraph:
- "@auth/dgraph-adapter"
dynamodb:
- "@next-auth/dynamodb-adapter"
- "@auth/dynamodb-adapter"
fauna:
- "@next-auth/fauna-adapter"

View File

@@ -8,14 +8,14 @@
</a>
<h3 align="center"><b>DynamoDB Adapter</b> - NextAuth.js / Auth.js</a></h3>
<p align="center" style="align: center;">
<a href="https://npm.im/@next-auth/dynamodb-adapter">
<a href="https://npm.im/@auth/dynamodb-adapter">
<img src="https://img.shields.io/badge/TypeScript-blue?style=flat-square" alt="TypeScript" />
</a>
<a href="https://npm.im/@next-auth/dynamodb-adapter">
<img alt="npm" src="https://img.shields.io/npm/v/@next-auth/dynamodb-adapter?color=green&label=@next-auth/dynamodb-adapter&style=flat-square">
<a href="https://npm.im/@auth/dynamodb-adapter">
<img alt="npm" src="https://img.shields.io/npm/v/@auth/dynamodb-adapter?color=green&label=@auth/dynamodb-adapter&style=flat-square">
</a>
<a href="https://www.npmtrends.com/@next-auth/dynamodb-adapter">
<img src="https://img.shields.io/npm/dm/@next-auth/dynamodb-adapter?label=%20downloads&style=flat-square" alt="Downloads" />
<a href="https://www.npmtrends.com/@auth/dynamodb-adapter">
<img src="https://img.shields.io/npm/dm/@auth/dynamodb-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,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 <info@balazsorban.com>"
],
"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:*"
}
}
}

View File

@@ -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({

View File

@@ -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",
]
}

12
pnpm-lock.yaml generated
View File

@@ -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

View File

@@ -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",