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!