Skip to content

Commit

Permalink
feat: introduce @auth/dgraph-adapter (#7792)
Browse files Browse the repository at this point in the history
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/dgraph-adapter": "0.0.0",
+  "@auth/dgraph-adapter": "0.0.0",
```

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

**Note:** This packages is published as ESM-only

`fetch` is not polyfilled anymore.

In older Node.js versions, you can use the  `--experimental-fetch` flag, or install `undici` and add the following line:

`globalThis.fetch ??= require("undici").fetch`
  • Loading branch information
balazsorban44 authored Jun 13, 2023
1 parent 43deda5 commit d414e01
Show file tree
Hide file tree
Showing 15 changed files with 73 additions and 49 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 @@ -21,7 +21,7 @@ body:
multiple: true
options:
- "Custom adapter"
- "@next-auth/dgraph-adapter"
- "@auth/dgraph-adapter"
- "@next-auth/dynamodb-adapter"
- "@next-auth/fauna-adapter"
- "@next-auth/firebase-adapter"
Expand Down
2 changes: 1 addition & 1 deletion .github/issue-labeler.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# https://github.com/github/issue-labeler#basic-examples

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

dynamodb:
- "@next-auth/dynamodb-adapter"
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ packages/next-auth/next
packages/*/*.js
packages/*/*.d.ts
packages/*/*.d.ts.map
packages/*/lib

# Development app
apps/dev/src/css
Expand Down
10 changes: 5 additions & 5 deletions packages/adapter-dgraph/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
</a>
<h3 align="center"><b>Dgraph Adapter</b> - NextAuth.js / Auth.js</a></h3>
<p align="center" style="align: center;">
<a href="https://npm.im/@next-auth/dgraph-adapter">
<a href="https://npm.im/@auth/dgraph-adapter">
<img src="https://img.shields.io/badge/TypeScript-blue?style=flat-square" alt="TypeScript" />
</a>
<a href="https://npm.im/@next-auth/dgraph-adapter">
<img alt="npm" src="https://img.shields.io/npm/v/@next-auth/dgraph-adapter?color=green&label=@next-auth/dgraph-adapter&style=flat-square">
<a href="https://npm.im/@auth/dgraph-adapter">
<img alt="npm" src="https://img.shields.io/npm/v/@auth/dgraph-adapter?color=green&label=@auth/dgraph-adapter&style=flat-square">
</a>
<a href="https://www.npmtrends.com/@next-auth/dgraph-adapter">
<img src="https://img.shields.io/npm/dm/@next-auth/dgraph-adapter?label=%20downloads&style=flat-square" alt="Downloads" />
<a href="https://www.npmtrends.com/@auth/dgraph-adapter">
<img src="https://img.shields.io/npm/dm/@auth/dgraph-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
39 changes: 23 additions & 16 deletions packages/adapter-dgraph/package.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,30 @@
{
"name": "@next-auth/dgraph-adapter",
"version": "1.0.6",
"description": "Dgraph adapter for next-auth.",
"name": "@auth/dgraph-adapter",
"version": "0.0.0",
"description": "Dgraph 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": "Arnaud Derbey <arnaud@derbey.dev>",
"contributors": [],
"main": "dist/index.js",
"contributors": [
"Balázs Orbán <info@balazsorban.com>"
],
"type": "module",
"types": "./index.d.ts",
"files": [
"dist",
"index.d.ts"
"*.js",
"*.d.ts*",
"lib",
"src"
],
"exports": {
".": {
"types": "./index.d.ts",
"import": "./index.js"
}
},
"license": "ISC",
"keywords": [
"next-auth",
Expand All @@ -29,25 +40,21 @@
"build": "tsc",
"test": "./tests/test.sh"
},
"peerDependencies": {
"jsonwebtoken": "^8.5.1",
"next-auth": "^4"
},
"devDependencies": {
"@next-auth/adapter-test": "workspace:*",
"@next-auth/tsconfig": "workspace:*",
"@types/jest": "^26.0.24",
"@types/jsonwebtoken": "^8.5.5",
"@types/node-fetch": "^2.5.11",
"jest": "^27.4.3",
"next-auth": "workspace:*",
"ts-jest": "^27.0.3"
"ts-jest": "^27.0.3",
"undici": "5.22.1"
},
"dependencies": {
"jsonwebtoken": "^8.5.1",
"node-fetch": "^2.6.1"
"@auth/core": "workspace:*",
"jsonwebtoken": "^8.5.1"
},
"jest": {
"preset": "@next-auth/adapter-test/jest"
}
}
}
20 changes: 10 additions & 10 deletions packages/adapter-dgraph/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,26 @@
* ## Installation
*
* ```bash npm2yarn2pnpm
* npm install next-auth @next-auth/dgraph-adapter
* npm install next-auth @auth/dgraph-adapter
* ```
*
* @module @next-auth/dgraph-adapter
* @module @auth/dgraph-adapter
*/
import { client as dgraphClient } from "./client"
import { format } from "./utils"
import type { Adapter } from "next-auth/adapters"
import type { DgraphClientParams } from "./client"
import * as defaultFragments from "./graphql/fragments"
import { client as dgraphClient } from "./lib/client"
import { format } from "./lib/utils"
import type { Adapter } from "@auth/core/adapters"
import type { DgraphClientParams } from "./lib/client"
import * as defaultFragments from "./lib/graphql/fragments"

export type { DgraphClientParams, DgraphClientError } from "./client"
export type { DgraphClientParams, DgraphClientError } from "./lib/client"

/** This is the interface of the Dgraph adapter options. */
export interface DgraphAdapterOptions {
/**
* The GraphQL {@link https://dgraph.io/docs/query-language/fragments/ Fragments} you can supply to the adapter
* to define how the shapes of the `user`, `account`, `session`, `verificationToken` entities look.
*
* By default the adapter will uses the [default defined fragments](https://github.com/nextauthjs/next-auth/blob/main/packages/adapter-dgraph/src/graphql/fragments.ts)
* By default the adapter will uses the [default defined fragments](https://github.com/nextauthjs/next-auth/blob/main/packages/adapter-dgraph/src/lib/graphql/fragments.ts)
* , this config option allows to extend them.
*/
fragments?: {
Expand All @@ -48,7 +48,7 @@ export { format }
*
* ```ts title="pages/api/auth/[...nextauth].js"
* import NextAuth from "next-auth"
* import { DgraphAdapter } from "@next-auth/dgraph-adapter"
* import { DgraphAdapter } from "@auth/dgraph-adapter"
*
* export default NextAuth({
* providers: [],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import * as jwt from "jsonwebtoken"
import fetch from "node-fetch"

import type { HeadersInit } from "node-fetch"

export interface DgraphClientParams {
endpoint: string
Expand Down
File renamed without changes.
6 changes: 4 additions & 2 deletions packages/adapter-dgraph/tests/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { DgraphAdapter, format } from "../src"
import { client as dgraphClient } from "../src/client"
import * as fragments from "../src/graphql/fragments"
import { client as dgraphClient } from "../src/lib/client"
import * as fragments from "../src/lib/graphql/fragments"
import { runBasicTests } from "@next-auth/adapter-test"
import fs from "fs"
import path from "path"

import type { DgraphClientParams } from "../src"

globalThis.fetch ??= require("undici").fetch

const params: DgraphClientParams = {
endpoint: "http://localhost:8080/graphql",
authToken: "test",
Expand Down
2 changes: 1 addition & 1 deletion packages/adapter-dgraph/tests/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ dgraph/standalone

echo "Waiting 15 sec for db to start..." && sleep 15

head -n -1 src/graphql/schema.gql > tests/test.schema.gql
head -n -1 src/lib/graphql/schema.gql > tests/test.schema.gql
PUBLIC_KEY=$(sed 's/$/\\n/' tests/public.key | tr -d '\n')
echo "# Dgraph.Authorization {\"VerificationKey\":\"$PUBLIC_KEY\",\"Namespace\":\"https://dgraph.io/jwt/claims\",\"Header\":\"Authorization\",\"Algo\":\"RS256\"}" >> tests/test.schema.gql

Expand Down
25 changes: 21 additions & 4 deletions packages/adapter-dgraph/tsconfig.json
Original file line number Diff line number Diff line change
@@ -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",
]
}
8 changes: 4 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions turbo.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
"@auth/core#build",
"@auth/prisma-adapter#build",
"@auth/sveltekit#build",
"@next-auth/dgraph-adapter#build",
"@auth/dgraph-adapter#build",
"@next-auth/dynamodb-adapter#build",
"@next-auth/fauna-adapter#build",
"@next-auth/firebase-adapter#build",
Expand All @@ -78,7 +78,7 @@
"@auth/core#build",
"@auth/prisma-adapter#build",
"@auth/sveltekit#build",
"@next-auth/dgraph-adapter#build",
"@auth/dgraph-adapter#build",
"@next-auth/dynamodb-adapter#build",
"@next-auth/fauna-adapter#build",
"@next-auth/firebase-adapter#build",
Expand Down

1 comment on commit d414e01

@vercel
Copy link

@vercel vercel bot commented on d414e01 Jun 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.