Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

366
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda