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

672
Views
Error al cargar el recurso: el servidor respondió con un estado de 401 (no autorizado) en REACT y NODE.js

Este es el código del lado del cliente REACT js en el error de la consola es este 1. No se pudo cargar el recurso: el servidor respondió con un estado de 401 (no autorizado) 2. Error de tipo no detectado: inventarios.mapa no es una función

 useEffect(() => { setDataLoading(true); const url = `http://localhost:5000/inventoryByEmail?email=${user.email}`; fetch(url, { headers: { authorization: `Bearer ${localStorage.getItem("access-token")}`, }, }) .then((res) => res.json()) .then((data) => { setInventories(data); setDataLoading(false); }); }, [user]);

Este es el código Nodejs del sitio del servidor

 function verifyJWT(req, res, next) { const authHeader = req.header.authorization; if (!authHeader) { return res.status(401).send({ message: "unauthorized access" }); } const token = authHeader.split(" ")[1]; jwt.verify(token, process.env.ACCESS_TOKEN_SECRET, (err, decoded) => { if (err) { return res.status(403).send({ message: "Forbidden access" }); } req.decoded = decoded; next(); }); }

y esta es la ruta api

 app.get("/inventoryByEmail", verifyJWT, async (req, res) => { const decodedEmail = req.decoded.email; const email = req.query.email; if (email === decodedEmail) { const query = { email: email }; const cursor = inventoryCollection.find(query); const result = await cursor.toArray(); res.send(result); } else { res.status(403).send({ message: "forbidden access" }); } });

¿Cómo solucionar este problema? ¡Muchas gracias por tu tiempo!

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

en su función verifiqueJWT es: req.headers.authorization; o si desea obtener el token: req.headers.authorization.split(' ')[1];

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!