Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

299
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda