Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Outdated Dgraph adapter: encoding, id overlap DgraphClientError: unknown field and edge runtime. #11273

Open
adriangalilea opened this issue Jun 27, 2024 · 4 comments · May be fixed by #11338
Open
Labels
adapters Changes related to the core code concerning database adapters bug Something isn't working triage Unseen or unconfirmed by a maintainer yet. Provide extra information in the meantime.

Comments

@adriangalilea
Copy link

adriangalilea commented Jun 27, 2024

Adapter type

@auth/dgraph-adapter

Environment

  System:
    OS: macOS 14.4.1
    CPU: (10) arm64 Apple M2 Pro
    Memory: 461.52 MB / 32.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 22.1.0 - /opt/homebrew/bin/node
    npm: 10.8.1 - /opt/homebrew/bin/npm
    pnpm: 8.6.7 - /opt/homebrew/bin/pnpm
    bun: 1.1.7 - /opt/homebrew/bin/bun
  Browsers:
    Brave Browser: 123.1.64.122
    Chrome: 126.0.6478.116
    Safari: 17.4.1
  npmPackages:
    @auth/dgraph-adapter: ^2.4.1 => 2.4.1 
    next: 14.1.4 => 14.1.4 
    next-auth: ^5.0.0-beta.19 => 5.0.0-beta.19 
    react: ^18.2.0 => 18.3.1 

Reproduction URL

https://github.com/adriangalilea/next-auth-example

Describe the issue

There are several issues with the Dgraph adapter:

1. JWT session and @auth directive

update

Fixed it and pushed it on the pull request.

original

Dgraph only works with HS256 or RS256 algorithms.

This is no longer true.

So this area of the docs can be removed for simplicity, once tested.

2. DgraphClientError: unknown field

update 2

Dgraph has

The @id directive is used for external identifiers, such as email addresses.

So the right solution may be doing this, I never quite understood why next-auth insist in handling id's itself.

However I'll continue overriding it and respecting Dgraph internal id's as I suspect it'd be better for performance.

update

Patched the Dgraph adapter so that it respects dgraph internal id.

repo branch

original

I spent way too many hours debugging this until I realised that it's the fact that Dgraph doesn't accept external id's.

Currently there is an open PR

This error completely prevents the use of the Dgraph adapter.

3. The edge runtime does not support Node.js 'crypto' module.

update:

I managed to fix the edge runtime issue by following Guides/Edge Compatibility

Fix can be seen here

original message:

 ⨯ 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 (....next/server/middleware.js:84:1)
    at __webpack_require__ (..../.next/server/edge-runtime-webpack.js:37:33)
    at fn (.../.next/server/edge-runtime-webpack.js:285:21)
    at eval (webpack-internal:///(middleware)/./middleware.ts:7:63)
    at (middleware)/./middleware.ts (.../.next/server/middleware.js:95:1) {
  middleware: true
}

I haven't identified specifically what part of the adapter is causing this, but it's def not up to date to be ran on the edge, thus can't check if user is logged in on the middleware, I know there's been some debate around edge runtime and auth, but I think it should be consistent with the rest of auth.js regardless.

How to reproduce

  1. Install Dgraph adapter
  2. Nothing works.

Expected behavior

Working adapter.

@adriangalilea adriangalilea added adapters Changes related to the core code concerning database adapters bug Something isn't working triage Unseen or unconfirmed by a maintainer yet. Provide extra information in the meantime. labels Jun 27, 2024
@adriangalilea
Copy link
Author

Updated 3. as I found the solution following the docs and seems not related to Dgraph adapter.

@adriangalilea
Copy link
Author

Updated 2. as I managed to patch the dgraph-adapter so that it doesn't use id on user

repo

@adriangalilea
Copy link
Author

adriangalilea commented Jun 28, 2024

Update 2 on 2.

Dgraph has introduces since this adapter:

The @id directive is used for external identifiers, such as email addresses.

So the right solution may be doing this, I never quite understood why next-auth insist in using his own id's rather than allow internal db id's.

Seems to be intentional and never answered by @balazsorban44

@adriangalilea
Copy link
Author

Also updated JWT to HS512, removed the section of the docs, documented the code and respect backwards compatibility.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
adapters Changes related to the core code concerning database adapters bug Something isn't working triage Unseen or unconfirmed by a maintainer yet. Provide extra information in the meantime.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant