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

480
Views
La propiedad '_id' no existe en el tipo 'cadena | JwtPayload'. La propiedad '_id' no existe en el tipo 'cadena'

Como puede ver en el código de NodeJS, tomo al usuario del token de Postman proporcionado en la URL, pero estoy luchando por recuperar la propiedad _id del número de token dado. Lo que quiero es esa identificación en decoded._id para poder usar esa identificación en operaciones posteriores

 const jwt = require('jsonwebtoken') const User = require('../model/users') const auth = async (req, res, next) => { try { const token = req.header('Authorization').replace('Bearer', '') const decoded = jwt.verify(token, 'thisisfromabhishek') `the property _id does not exist on decoded` const user = await User.findOne({ _id: decoded._id, 'tokens.token': token }) if (!user) { throw new Error() } req.token = token req.user = user next() } catch (e) { res.status(401).send({ error: 'Please authenticate.' }) } } module.exports = auth
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Typescript no sabe acerca de _id en token. La declaración de datos debería ayudar.

 interface JwtPayload { _id: string } const { _id } = jwt.verify(token, 'thisisfromabhishek') as JwtPayload req.user = await User.findOne({ _id, 'tokens.token': token })
about 4 years ago · Juan Pablo Isaza Report

0

no has dado espacio después de Bearer.

 const token = req.header('Authorization').replace('Bearer', '') //here is the problem place space after Bearer const decoded = jwt.verify(token, 'thisisfromabhishek')

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!