0

I've a problem when i use _middleware in next js , I want to get the jwt token and check it in that _middleware , that's my code :

import {NextResponse} from "next/server";
import {verify} from "jsonwebtoken";

export async function middleware(req) {

        let { cookies } = req;

        let token = await cookies.jwt
        
        let url = req.url;
        
        if(url.includes('/dashbord')){
            if(token === undefined) return NextResponse.redirect(process.env.NEXTAUTH_URL+'login');
            try {
                 verify(token,process.env.PASSWORD_SECRET);
                return NextResponse.next();
            } catch (err) {
                return NextResponse.redirect(process.env.NEXTAUTH_URL+'login');
            }
        }
        return NextResponse.next();
}

The code works in the localhost very well but when i deploy it , it give me an error **Failed to compile. ** All the envirement variables are setting

juliomalves
  • 42,130
  • 20
  • 150
  • 146

1 Answers1

1

Yeh, I'm with the sambe problem. Looks like we can't use node library in next middleware. We could try use a client library.

Next.js middleware Module not found: Can't resolve 'fs'