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

998
Views
express-jwt - typeError: hecho no es una función

Estoy usando express-jwt para controlar los privilegios de usuario de mi proyecto de inicio, pero recibo un error cuando intento solicitar acceso (usando Postman) a una API a la que solo puede acceder el administrador. Este es mi documento authJwt:

 import { expressjwt } from "express-jwt"; import dotenv from 'dotenv'; dotenv.config(); const secretJwt = process.env.JWT_SECRET; function authJwt() { return expressjwt({ secret: secretJwt, algorithms: ['HS256'], //https://jwt.io/ isRevoked: isRevoked }) .unless({ path: [ '/users/login', '/users/register', { url: /\/categories(.*)/, // (https://regex101.com/) methods: ['GET', 'OPTIONS'] } ] }) } async function isRevoked(req, payload, done) { if(!payload.isAdmin) { done(null, true) } done(); } export default authJwt;

El error que estoy recibiendo es:

 TypeError: done is not a function<br> &nbsp; &nbsp;at Object.isRevoked (file:///C:/Users/OneDrive%20-%20GfK/Documents/IPCA/Programa%C3%A7%C3%A3o%20Web/PWeb%20-%20Projecto/FTA%20/backend/middlewares/jwt.js:42:9)<br> &nbsp; &nbsp;at C:\Users\\OneDrive - GfK\Documents\IPCA\Programação Web\PWeb - Projecto\FTA\backend\node_modules\express-jwt\dist\index.js:157:54<br> &nbsp; &nbsp;at step (C:\Users\rui.lopes\OneDrive - GfK\Documents\IPCA\Programação Web\PWeb - Projecto\FTA\backend\node_modules\express-jwt\dist\index.js:56:23)<br> &nbsp; &nbsp;at Object.next (C:\Users\rui.lopes\OneDrive - GfK\Documents\IPCA\Programação Web\PWeb - Projecto\FTA\backend\node_modules\express-jwt\dist\index.js:37:53)<br> &nbsp; &nbsp;at fulfilled (C:\Users\rui.lopes\OneDrive - GfK\Documents\IPCA\Programação Web\PWeb - Projecto\FTA\backend\node_modules\express-jwt\dist\index.js:28:58)<br> &nbsp; &nbsp;at processTicksAndRejections (node:internal/process/task_queues:96:5)
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

const {expressjwt: expressJwt} = require('express-jwt')

exportaciones.authJwt = expressJwt ({ secreto: secretJwt, algoritmos: ['HS256'], //https://jwt.io/ isRevoked: isRevoked })....

about 4 years ago · Juan Pablo Isaza Report

0

Según las actualizaciones: la función isRevoked tenía (req, payload, cb), ahora puede devolver una promesa y recibe (req, token). token tiene encabezado y carga útil.

IsRevoked = (req: express.Request, token: jwt.Jwt | undefined) => Promise<boolean`>

esto funcionó para mí:

 async function isRevoked(req, token){ if(!token.payload.isAdmin) { return true; } }
about 4 years ago · Juan Pablo Isaza Report
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!