Next.js Discord

Discord Forum

JWT Token verification in Middleware

Unanswered
Ferruginous Hawk posted this in #help-forum
Open in Discord
Ferruginous HawkOP
My app is set up to create and store (access and refresh) cookies for signed in user. However, when I try to verify cookies in my Next.js middleware, I am getting some errors.

First, I used my custom verifyToken function, and then I directy import jwt from "jsonwebtoken".

For the former, I get error that Error in middleware: TypeError: Function has non-object prototype 'undefined' in instanceof check
And for the latter, Error in middleware: Error: The edge runtime does not support Node.js 'crypto' module.

Question: How to best handle tokens and cookies in Next.js middleware.

2 Replies