# Next-Auth Dgraph DQL/GraphQL Database Adapter

**URL:** <https://discuss.dgraph.io/t/next-auth-dgraph-dql-graphql-database-adapter/14760>\
**Category:** App Development\
**Tags:** graphql, auth, nextjs, next-auth\
**Created:** [June 29, 2021, 3:03pm UTC](https://discuss.dgraph.io/t/next-auth-dgraph-dql-graphql-database-adapter/14760 "2021-06-29T15:03:51Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![amaster507](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/amaster507/32/4123_2.png) [@amaster507](https://discuss.dgraph.io/u/amaster507)\
**Post date:** [June 29, 2021, 3:03pm UTC](https://discuss.dgraph.io/t/next-auth-dgraph-dql-graphql-database-adapter/14760/1 "2021-06-29T15:03:51Z")

</div>

Has anyone created a Dgraph DQL/GraphQL database adapter for next-auth?

> **[Create an adapter | NextAuth.js](https://next-auth.js.org/tutorials/creating-a-database-adapter)**
>
> Using a custom adapter you can connect to any database back-end or even several different databases. Official adapters created and maintained by our community can be found in the adapters packages. Feel free to add a custom adapter from your project...

Thinking this probably varies as schema is different, just beginning to learn next-auth, so feel free to chime in with any advice in this area.

---

<div class="post-metadata">

**Author:** ![jdgamble555](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/jdgamble555/32/7503_2.png) [@jdgamble555](https://discuss.dgraph.io/u/jdgamble555)\
**Post date:** [June 29, 2021, 11:02pm UTC](https://discuss.dgraph.io/t/next-auth-dgraph-dql-graphql-database-adapter/14760/2 "2021-06-29T23:02:24Z")

</div>

With firebase auth? You need an auth provider to use it…

J

---

<div class="post-metadata">

**Author:** ![amaster507](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/amaster507/32/4123_2.png) [@amaster507](https://discuss.dgraph.io/u/amaster507)\
**Post date:** [June 30, 2021, 4:26am UTC](https://discuss.dgraph.io/t/next-auth-dgraph-dql-graphql-database-adapter/14760/3 "2021-06-30T04:26:52Z")

</div>

Well not firebase. First pass we want to just use our database as the source for password based credentials. And I believe we (@pbassham) got that working with just a simple signin callback. But we need to persist sessions to a database to be able to use those sessions by pointer reference in SSR with Next.js. There is a bunch (really just a few) of adapters made already for working with different sql flavors, mongo, dynamodb, and fauna. But there is nothing for Dgraph. We don’t want to silo this data away from our graph but connect it. Why have a graph if we have to keep siloing parts of connected data out to other sources. So building off from the prisma adapter I believe would be the way to go. It would require a minimum schema to make it work, but that is not the limitation to what that data can connect to. Eventually we want to make it so that a user can authenticate through whatever provider they want and we link it to the same user by email address. So we offload all authentication to any provider but store in graph the users sessions so we can manage and track them within one cohesive graph.

---

<div class="post-metadata">

**Author:** ![arnaudDerbey](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/arnaudderbey/32/8591_2.png) [@arnaudDerbey](https://discuss.dgraph.io/u/arnaudDerbey)\
**Post date:** [July 15, 2021, 11:46am UTC](https://discuss.dgraph.io/t/next-auth-dgraph-dql-graphql-database-adapter/14760/4 "2021-07-15T11:46:19Z")

</div>

Hello Amaster ! I’ve just push a PR for a Dgraph/graphql adapter ! 🎉  
[https://github.com/nextauthjs/adapters/pull/170](https://github.com/nextauthjs/adapters/pull/170)

Unfortunately, next-auth discourage the use of credentials in favor of OAuth and passwordless authentication. So this adapter and more generally the next-auth package won’t be useful if you want to use a password flavored authentication flow in combination with Dgraph.

---

<div class="post-metadata">

**Author:** ![adriangalilea](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/adriangalilea/32/11621_2.png) [@adriangalilea](https://discuss.dgraph.io/u/adriangalilea)\
**Post date:** [June 20, 2024, 9:45pm UTC](https://discuss.dgraph.io/t/next-auth-dgraph-dql-graphql-database-adapter/14760/5 "2024-06-20T21:45:03Z")

</div>

Hello,

First of all thanks for the adapter, and sorry to revive this thread, but I think is the right one to address this.

As far as I know, this approach is incompatible with edge runtime due [“Dgraph only works with HS256 or RS256 algorithms”](https://authjs.dev/getting-started/adapters/dgraph#jwt-session-and-auth-directive) and the need of jsonwebtoken.

Did anyone face this issue? When I use `auth` from the middleware I get:

```auto
 ⨯ Error: The edge runtime does not support Node.js 'crypto' module.
Learn More: https://nextjs.org/docs/messages/node-module-in-edge-runtime
    at <unknown> (webpack-internal:///(middleware)/./node_modules/next/dist/esm/server/web/globals.js:33)
    at Object.get (webpack-internal:///(middleware)/./node_modules/next/dist/esm/server/web/globals.js:33:19)
    at module.exports [as sign] (webpack-internal:///(middleware)/./node_modules/jsonwebtoken/sign.js:115:58)
    at client (webpack-internal:///(middleware)/./node_modules/@auth/dgraph-adapter/lib/client.js:28:73)
    at DgraphAdapter (webpack-internal:///(middleware)/./node_modules/@auth/dgraph-adapter/index.js:29:69)
    at eval (webpack-internal:///(middleware)/./auth.ts:39:81)
    at (middleware)/./auth.ts (file:///Users/adrian/Developer/self.fm/.next/server/middleware.js:84:1)
    at __webpack_require__ (file:///Users/adrian/Developer/self.fm/.next/server/edge-runtime-webpack.js:37:33)
    at fn (file:///Users/adrian/Developer/self.fm/.next/server/edge-runtime-webpack.js:285:21)
    at eval (webpack-internal:///(middleware)/./middleware.ts:7:63)
    at (middleware)/./middleware.ts (file:///Users/adrian/Developer/self.fm/.next/server/middleware.js:95:1) {
  middleware: true
}

```

Any ideas on how to solve it?

How is next-auth dealing with HS512 while respecting the edge runtime?

Thanks!

---

<div class="post-metadata">

**Author:** ![adriangalilea](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/adriangalilea/32/11621_2.png) [@adriangalilea](https://discuss.dgraph.io/u/adriangalilea)\
**Post date:** [June 26, 2024, 8:09am UTC](https://discuss.dgraph.io/t/next-auth-dgraph-dql-graphql-database-adapter/14760/6 "2024-06-26T08:09:57Z")

</div>

I can’t edit the last message so I’ll append a new one.

First, dgraph now accepts HS512, so the suggestions on the adapter, using alternative encoding methods, seems dated.  
Second, I’m running into a unknown field issues, just realized it’s because next-auth is sending it’s own ID, which dgraph doesn’t accept, I wonder how can this be fixed, and when did this change in dgraph.
