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

235
Views
¿Cómo saber el ID de usuario del usuario registrado con JWT?

Quiero saber el ID de usuario con esta ruta usando o no el token JWT cada vez que quiero agregar en mi base de datos los elementos vinculados en los que hago clic:

 .post(parseArticle, (req,res) => { db.query("SELECT * FROM articles WHERE id_article = ?", [[ req.articleId]], function (err,result) { if (err) throw err; let token = req.headers['x-access-token'] || req.headers['authorization'] || req.cookies.token; if (!!token && token.startsWith('Bearer ')) { token = token.slice(7, token.length); } if (token) { jwt.verify(token, 'RANDOM_TOKEN_SECRET', (err, decoded) => { if (err) { return res.status(401).json('token_not_valid'); } else { req.userId = decoded.userId db.query("INSERT INTO panier_item(id_article,image,name,description,price,iduser) VALUES (?)", [[req.articleId,result[0].image, result[0].name, result[0].description, result[0].price, req.userId]], function (err,result) {if (err) throw err;}) req.decoded = decoded; } // on envoie l'article ajouté à l'utilisateur res.status(200).json({message: "Good!"}) })}})})

pero siempre obtengo NULL cuando quiero INSERTAR EN ese req.userId: "INSERT INTO panier_item(id_article,image,name,description,price,iduser) VALUES (5, 'https://www.cdiscount.com/pdt2/6/0/6/1/300x300/spo4013771089606/rw/sponeta-table-tennis-de-table-table-ping-pong-co.jpg', 'Table de ping-pong', 'Le moment de détente que tout le monde attend entre deux pauses !', '400', NULL)"

Gracias,

over 4 years ago · Santiago Trujillo
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!