Error: The edge runtime does not support Node.js 'crypto' module
This error only come up after I added middleware
Searched issue on GitHub , no report about it on better-auth (or I am blind)
tried to search more info appears that next-auth also have same issue as better-auth
I need help here: How to bypass it or we have to not use middleware until it fixes?
My middleware.ts:
What I did:
1. I create new next js app to try out better auth
2. I follow the installation guide here
3. I install mongo db adapter guide here
4. I copy and modify
middleware.ts
to work with my directory
5. bug ->This error occurs (the Image)
The error:
My attempt:
I tried adding into config
It seems like a next
issue but I make a help request here
Next-auth also have the sameissue:
- Nextjs middleware edge runtime problem (with Mysql database with Knex package)
After I try adding into config from next js docs:
Haven't tried the canary version yetInstallation | Better Auth
Learn how to configure Better Auth in your project.
MongoDB Adapter | Better Auth
Integrate Better Auth with MongoDB.
GitHub
Nextjs middleware edge runtime problem (with Mysql database with Kn...
Environment System: OS: Windows 10 10.0.19045 CPU: (8) x64 Intel(R) Core(TM) i7-7700K CPU @ 4.20GHz Memory: 19.24 GB / 31.96 GB Binaries: Node: 21.1.0 - C:\Program Files\nodejs\node.EXE Yarn: 1.22....
Routing: Middleware | Next.js
Learn how to use Middleware to run code before a request is completed.

1 Reply
You have to use an API request from your Middleware to the route handler.