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

88
Vistas
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
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