I want to be able to redirect my MEAN app to the Login page whenever there is no valid login.
I have a component, which on ngOninit() calls an API route.
The API route looks like:
router.get("/route", isLoggedIn, (req, res) => {
});
Where isLoggedIn is:
function isLoggedIn(req, res, next) {
if (req.isAuthenticated()) {
return next();
} else {
console.log("Not Logged in");
res.redirect("http://localhost:3000/login");
}
}
When res.redirect("http://localhost:3000/login") is executed, it throws an error in the console: "Template parse error". I guess this has something to do with the component which called the API waiting for the response from the API.
What's the best way to accomplish this?