Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

376
Vistas
Unauthenticated error in the browser, but it perfectly works on postman

I have this piece of code that works fine on postman when I set the header to the token generated from the access token. but when I'm using the same piece of code on the browser when I log in, I get the authorization access, but the moment I manually input the new router, I get an unauthorized error.

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");
    }
});

};

the verifyAndAuth middleware is added to every route for example:

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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda