I'm having a nodejs (express) as a server side and an angular 6 as client.In the server I have middlewear function that makes a session check. In case where the session is invalid or not exists, I would like to send a response to the client so that it can react to it. I thought of returning a response code of 401 from the server, and make some kind of listener\route-guard\HttpInterceptor in the client, so - it can manage the situation in the client (redirect it to the login page, for example). Here is my code in the server:
router.use('/', (req, res, next) =>
{
if (!req.session.user)
{
res.status(401);
}
else{
next();
}
})
How can I catch\listen to this response in the angular app ?