Okay, so I want to verify jwt
in nuxt middleware. It might be a bad idea. Please correct me. But I also need a solution. I learned that, middleware runs on both client and server. So, here’s my code
<code>import jwt from 'jsonwebtoken'
export default defineNuxtRouteMiddleware((to, from) => {
if (import.meta.server) {
console.log('okay', jwt.verify('eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c', 'my-token'))
}
})
</code>
<code>import jwt from 'jsonwebtoken'
export default defineNuxtRouteMiddleware((to, from) => {
if (import.meta.server) {
console.log('okay', jwt.verify('eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c', 'my-token'))
}
})
</code>
import jwt from 'jsonwebtoken'
export default defineNuxtRouteMiddleware((to, from) => {
if (import.meta.server) {
console.log('okay', jwt.verify('eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c', 'my-token'))
}
})
It’s a global middleware. The warning I am getting is
Module "util" has been externalized for browser compatibility. Cannot access "util.inherits" in client code. See https://vitejs.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.
. And the error is Uncaught TypeError: util.inherits is not a function
. What am I missing here?