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

90
Visualizações
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 à 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