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

[AdapterError] NextAuth with Drizzle Adapter #12411

Open
Maisaan opened this issue Dec 21, 2024 · 5 comments
Open

[AdapterError] NextAuth with Drizzle Adapter #12411

Maisaan opened this issue Dec 21, 2024 · 5 comments
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

@Maisaan
Copy link

Maisaan commented Dec 21, 2024

Adapter type

@auth/drizzle-adapter

Environment

  System:
    OS: macOS 15.2
    CPU: (10) arm64 Apple M2 Pro
    Memory: 1.09 GB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 22.12.0 - ~/.nvm/versions/node/v22.12.0/bin/node
    npm: 10.9.0 - ~/.nvm/versions/node/v22.12.0/bin/npm
    pnpm: 9.7.0 - ~/Library/pnpm/pnpm
  Browsers:
    Safari: 18.2
  npmPackages:
    @auth/drizzle-adapter: ^1.7.2 => 1.7.4 
    next: 15.1.2 => 15.1.2 
    next-auth: 5.0.0-beta.25 => 5.0.0-beta.25 
    react: ^19.0.0 => 19.0.0 

Reproduction URL

https://github.com/Maisaan/drizzle-adapter-error

Describe the issue

Getting the following errors when trying to access req.auth inside of middleware, when middleware file is deleted this works without errors. I want to setup basic auth redirects.

I have updated next-auth-example template with my code to recreate error

[auth][error] AdapterError: Read more at https://errors.authjs.dev#adaptererror
[auth][cause]: Error: The edge runtime does not support Node.js 'net' module.
Learn More: https://nextjs.org/docs/messages/node-module-in-edge-runtime
    at Object.construct (webpack-internal:///(middleware)/./node_modules/.pnpm/[email protected][email protected][email protected][email protected]/node_modules/next/dist/esm/server/web/globals.js:59:19)
    at createSocket (webpack-internal:///(middleware)/./node_modules/.pnpm/[email protected]/node_modules/postgres/src/connection.js:148:11)
    at Timeout.connect [as _onTimeout] (webpack-internal:///(middleware)/./node_modules/.pnpm/[email protected]/node_modules/postgres/src/connection.js:345:31)
    at listOnTimeout (node:internal/timers:594:17)
    at process.processTimers (node:internal/timers:529:7)
[auth][details]: {}
[auth][error] SessionTokenError: Read more at https://errors.authjs.dev#sessiontokenerror
[auth][cause]: Error: The edge runtime does not support Node.js 'net' module.
Learn More: https://nextjs.org/docs/messages/node-module-in-edge-runtime
    at Object.construct (webpack-internal:///(middleware)/./node_modules/.pnpm/[email protected][email protected][email protected][email protected]/node_modules/next/dist/esm/server/web/globals.js:59:19)
    at createSocket (webpack-internal:///(middleware)/./node_modules/.pnpm/[email protected]/node_modules/postgres/src/connection.js:148:11)
    at Timeout.connect [as _onTimeout] (webpack-internal:///(middleware)/./node_modules/.pnpm/[email protected]/node_modules/postgres/src/connection.js:345:31)
    at listOnTimeout (node:internal/timers:594:17)
    at process.processTimers (node:internal/timers:529:7)

Instead of a middleware i am currently using an HOC to check if session exists and redirect to auth screen, this is not ideal but works for now.

How to reproduce

  • Clone repo and pnpm install
  • Create env file as per .env.local.example
  • Use npx drizzle-kit push to update supabase
  • Attempt to sign in

Expected behavior

Authenticate user and redirect to home screen

@Maisaan Maisaan 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 Dec 21, 2024
@FabriBorgobello
Copy link

@Maisaan
Copy link
Author

Maisaan commented Dec 22, 2024

Yes, been over that. Afaik, DrizzleAdapter is edge compatible, and i wish to use the database strategy because i want to have a finer control over the users, with permissions and roles. When you lazy initialise or split configs you loose database functionality and thats not how i want it.

@xibluespider
Copy link

I encountered a similar error. I was able to resolve it after i removed the import of server side database interaction function from client side related hook. Hope this helps.

@FabriBorgobello
Copy link

I encountered a similar error. I was able to resolve it after i removed the import of server side database interaction function from client side related hook. Hope this helps.

That's good news! Could you please show me how you did it? Thanks!

@xibluespider
Copy link

xibluespider commented Dec 26, 2024

Hello @FabriBorgobello,

I uploaded a branch toShowError for you, here. Kindly look into it. Check /test page, here, later check searchUser route handler, here.

I was implementing search feature, had to interact with database. Instead of directly using the database function (which caused the error for me as shown below), which is supposed to be used server side rather than client side, I implemented an api handler for it that indirectly works with the database function.

error

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

No branches or pull requests

3 participants