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

373
Views
Error no autenticado en el navegador, pero funciona perfectamente en cartero

Tengo este fragmento de código que funciona bien en cartero cuando configuro el encabezado en el token generado a partir del token de acceso. pero cuando estoy usando el mismo código en el navegador cuando inicio sesión, obtengo el acceso de autorización, pero en el momento en que ingreso manualmente el nuevo enrutador, aparece un error no autorizado.

 const verifyToken = (req, res, next) => { const authHeader = req.headers["authorization"]; if (authHeader) { const token = authHeader.split(" ")[1]; jwt.verify(token, process.env.jwtToken, (err, user) => { if (err) { res.status(500).json("Invalid Token"); } else { req.user = user; next(); } }); } else { res.status(500).json("You are not authenticated"); }

};

 const verifyAndAuth = (req, res, next) => { verifyToken(req, res, () => { if (req.params.id === req.user.id) { next(); } else { res.status(500).json("You are not verified"); } });

};

el middleware verificarAndAuth se agrega a cada ruta, por ejemplo:

 router.get("/", admin, async (req, res) => { try { const noteData = await users.find(); res.status(200).json(noteData) } catch (err) { res.status(500).json(err) }

});

about 4 years ago · Juan Pablo Isaza
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!