Token inválido o expirado en middleware: jwt expired
[Nest] 14874 - 06/09/2025, 11:23:58 PM ERROR [ExceptionsHandler] Cannot read properties of undefined (reading 'query')
TypeError: Cannot read properties of undefined (reading 'query')
at PublicacionController.findAllPaginated (/Users/kevinazua/Desktop/tesis-backend/src/publicacion/publicacion.controller.ts:25:44)
at /Users/kevinazua/Desktop/tesis-backend/node_modules/@nestjs/core/router/router-execution-context.js:38:29
at InterceptorsConsumer.transformDeferred (/Users/kevinazua/Desktop/tesis-backend/node_modules/@nestjs/core/interceptors/interceptors-consumer.js:31:33)
at /Users/kevinazua/Desktop/tesis-backend/node_modules/@nestjs/core/interceptors/interceptors-consumer.js:18:86
at AsyncResource.runInAsyncScope (node:async_hooks:203:9)
at bound (node:async_hooks:235:16)
at Observable._subscribe (/Users/kevinazua/Desktop/tesis-backend/node_modules/rxjs/src/internal/observable/defer.ts:55:15)
at Observable.Observable._trySubscribe (/Users/kevinazua/Desktop/tesis-backend/node_modules/rxjs/src/internal/Observable.ts:244:19)
at <anonymous> (/Users/kevinazua/Desktop/tesis-backend/node_modules/rxjs/src/internal/Observable.ts:234:18)
at Object.errorContext (/Users/kevinazua/Desktop/tesis-backend/node_modules/rxjs/src/internal/util/errorContext.ts:29:5)
Token inválido o expirado en middleware: jwt expired
[Nest] 14874 - 06/09/2025, 11:24:01 PM ERROR [ExceptionsHandler] Cannot read properties of undefined (reading 'query')
TypeError: Cannot read properties of undefined (reading 'query')
at PublicacionController.findAllPaginated (/Users/kevinazua/Desktop/tesis-backend/src/publicacion/publicacion.controller.ts:25:44)
at /Users/kevinazua/Desktop/tesis-backend/node_modules/@nestjs/core/router/router-execution-context.js:38:29
at InterceptorsConsumer.transformDeferred (/Users/kevinazua/Desktop/tesis-backend/node_modules/@nestjs/core/interceptors/interceptors-consumer.js:31:33)
at /Users/kevinazua/Desktop/tesis-backend/node_modules/@nestjs/core/interceptors/interceptors-consumer.js:18:86
at AsyncResource.runInAsyncScope (node:async_hooks:203:9)
at bound (node:async_hooks:235:16)
at Observable._subscribe (/Users/kevinazua/Desktop/tesis-backend/node_modules/rxjs/src/internal/observable/defer.ts:55:15)
at Observable.Observable._trySubscribe (/Users/kevinazua/Desktop/tesis-backend/node_modules/rxjs/src/internal/Observable.ts:244:19)
at <anonymous> (/Users/kevinazua/Desktop/tesis-backend/node_modules/rxjs/src/internal/Observable.ts:234:18)
at Object.errorContext (/Users/kevinazua/Desktop/tesis-backend/node_modules/rxjs/src/internal/util/errorContext.ts:29:5)
Whats happening?
The issue is that I need to properly import and use the @Req() decorator, and there might be a JWT token issue. Let me fix both problems:
I've added the missing @Req import to the controller. The issues were:
Req to the imports from @nestjs/commonUpdate the Authorization header in Postman with the new token:
Authorization: Bearer YOUR_NEW_JWT_TOKEN/listar endpoint specifically:Since this is a public endpoint for listing publications, you might want to make it accessible without authentication. If so, we should remove any JWT guards from this endpoint.
The console should now show:
Full request query: { estado: 'aprobado', page: '1', limit: '1' }
Request URL: /listar?estado=aprobado&page=1&limit=1
Extracted query params: { page: '1', limit: '1', search: undefined, fechaInicio: undefined, fechaFin: undefined, estado: 'aprobado' }There is a problem in solicitudes-adopcion of my requests its giving a 500 and also in the /api/solicitudes-adopcion/11
its not working
[Nest] 16869 - 06/10/2025, 1:47:53 AM ERROR [ExceptionsHandler] Cannot read properties of undefined (reading 'userId')
TypeError: Cannot read properties of undefined (reading 'userId')
at SolicitudesAdopcionController.findMyRequests (/Users/kevinazua/Desktop/tesis-backend/src/solicitudes-adopcion/solicitudes-adopcion.controller.ts:49:60)
at /Users/kevinazua/Desktop/tesis-backend/node_modules/@nestjs/core/router/router-execution-context.js:38:29
at InterceptorsConsumer.transformDeferred (/Users/kevinazua/Desktop/tesis-backend/node_modules/@nestjs/core/interceptors/interceptors-consumer.js:31:33)
at /Users/kevinazua/Desktop/tesis-backend/node_modules/@nestjs/core/interceptors/interceptors-consumer.js:18:86
at AsyncResource.runInAsyncScope (node:async_hooks:203:9)
at bound (node:async_hooks:235:16)
at Observable._subscribe (/Users/kevinazua/Desktop/tesis-backend/node_modules/rxjs/src/internal/observable/defer.ts:55:15)
at Observable.Observable._trySubscribe (/Users/kevinazua/Desktop/tesis-backend/node_modules/rxjs/src/internal/Observable.ts:244:19)
at <anonymous> (/Users/kevinazua/Desktop/tesis-backend/node_modules/rxjs/src/internal/Observable.ts:234:18)
at Object.errorContext (/Users/kevinazua/Desktop/tesis-backend/node_modules/rxjs/src/internal/util/errorContext.ts:29:5)
The issue is that the @GetUser() decorator is missing from the controller methods. Let me fix the solicitudes-adopcion controller:
I've fixed all the issues in the solicitudes-adopcion controller:
@GetUser() Decorators: All methods that need user information now have the @GetUser() decorator@Body() Decorator: The create method now properly extracts the request bodyParseIntPipe: All ID parameters now use ParseIntPipe for proper validationGET /api/solicitudes-adopcion/user/my-requests - Now properly gets user IDGET /api/solicitudes-adopcion/11 - Now works with proper parameter parsingPOST /api/solicitudes-adopcion - Now properly extracts request body@GetUser() decorators - Methods couldn't access the authenticated user@Body() decorator - The create method couldn't access request body# Get user's own requests (should work now)
GET /api/solicitudes-adopcion/user/my-requests
# Get specific request (should work now)
GET /api/solicitudes-adopcion/11
# Create new request (should work now)
POST /api/solicitudes-adopcionAll the 500 errors should now be resolved! 🎉