Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

298
Views
How to check cookies in _middleware on Next.js

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

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!