Middleware Issues in Next.js Using Drizzle, Supabase, and NextAuth
Hi everyone! Is there anyone here who has successfully implemented middleware with Drizzle, Supabase, and NextAuth? I'm using Next.js.
I initially encountered this error: Reading from "cloudflare:sockets" is not handled by plugins (Unhandled scheme). However, after deleting and reinstalling the Postgres package, this error has disappeared.
Now, during login, I'm facing this issue:
[auth][error] JWTSessionError: Read more at https://errors.authjs.dev#jwtsessionerror
[auth][cause]: Error: The edge runtime does not support Node.js 'net' module.
Is it not possible to use Next.js, Drizzle, Supabase, and NextAuth in an edge environment within middleware? What am I doing wrong? My code is visible in the pictures. Thanks in advance for the help!
Auth.js | Errors
Authentication for the Web
5 Replies
I'm sure that Drizzle is causing the problem because I separated the auth into edge and no edge, and when I remove the database calls, the login works fine. I just don't understand what the issue could be.
it might be bcrypt
if its cf there is an edge version
Yes, I thought about that too, but unfortunately, it's not bcrypt. On one hand, this code works perfectly fine with Neon DB because I originally wrote it there and copied it over from a fully functioning project. However, I want to solve it with Supabase here, because I couldn't find much information on how to self-host Neon, and my Docker knowledge is limited. Plus, if I'm correct, Neon doesn't support real-time by default.
But to make sure it's not bcrypt, I removed the part of the code related to it from the edge, so only the necessary checks run in the middleware, but it still doesn't work and throws the same error. It only works properly if I completely remove the database queries from the edge where is my comment.
doesnt build normally tell you if something wont work in node edge runtime
i assume you have this
https://developers.cloudflare.com/workers/tutorials/postgres/#enable-nodejs-compatibility
Thanks for the suggestion! I’m a bit confused, though since the documentation link you sent seems to focus on Cloudflare workers, which is a bit different from Next.js. Were you suggesting I should configure something in next.config.js? My connection string in the environment variables works fine, and I set up Drizzle according to the documentation on their site (I shared the setups in the screenshots above). Could you help clarify what you think might be causing the issue?