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

91
Views
API call resulting in failure - Passport NodeJS EXpress Mongo NewsAPI

I am building a web app, it has a landing screen post user sign in This landing screen is meant to display list of news article from a REST API - NEWSAPI

Server.js


const {
  checkAuth,
  checkNotAuth,
} = require("./auth");

initializePassport(
  passport,
  async (email) => {
    const userAvailable = await User.findOne({ email });
    return userAvailable;
  },
  async (id) => {
    const userAvailable = await User.findOne({ _id: id });
    return userAvailable;
  }
);

app.get('/homepage',checkNotAuthenticated, async(req,res)=>{
  var category = req.params.category;
  try {
      var url = 'http://newsapi.org/v2/top-headlines?country=in&category=business' + '&apiKey=somekey';

      const news_get =await axios.get(url)
      res.render('homepage',{articles:news_get.data.articles, username: req.user.username, id: req.user._id})
      

  } catch (error) {
      if(error.response){
          console.log(error)
      }

  }
})



auth.js

function checkNotAuthreq, res, next) {
  if (req.isAuthenticated()) {
    return res.redirect("/homepage");
  }
  next();
}

function checkAuth(req, res, next) {
  if (req.isAuthenticated()) {
    return next();
  }
  res.redirect("/login");
}

module.exports = {
  checkNotAuthenticated,
  checkAuthenticated,
};

when I call the GET API on http://localhost/port#/homepage ---> I get a redirect to login page on Postman; instead of the loading the newsAPI details which is being called in the route /homepage In my application, all is good, its only in postman that's messing up Any help would be greatly appreciated. This is bogging me down big time. Please help!

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!