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

374
Views
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
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!