Next.js Discord

Discord Forum

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

Answered
LaPerm posted this in #help-forum
Open in Discord
Avatar
LaPermOP
In my 'middleware.ts', I was trying to get authentication header and decode it. I am using 'jsonwebtoken' library to create and validate jwts. But it would appear I can not use jsonwebtoken.verify() in my middleware as it requires Node.js runtime. Is there any way to switch to Node.js runtime from Edge runtime, or is there any other solution to my problem?

Sorry if my question is stupid!
Image
Answered by Asian black bear
No, you can't change the runtime and have to use a library that is Edge-compatible. If I'm not mistaken jose can be used.
View full answer

2 Replies

Avatar
Asian black bear
No, you can't change the runtime and have to use a library that is Edge-compatible. If I'm not mistaken jose can be used.
Answer
Avatar
LaPermOP
Thanks! jose exactly fixes this problem. Additionally I had to pass the token secret as utf-8 encoded buffer. I have attached the solution for anyone sharing the same problem.
Image