How to communicate from the back end to the front end in a MEAN stack application? How to communicate from the back end to the front end in a MEAN stack application? mongoose mongoose

How to communicate from the back end to the front end in a MEAN stack application?


What you can do is call an api to check whether the user is logged in or not in ngOnInit lifecycle hook,so every time your component loads you can check whether the session exists on backend and route accordingly.

 export class App implements OnInit{          constructor(){             //called first time before the ngOnInit()          }          ngOnInit(){           //CheckLogin() is a method in your service which calls your backend api             this.http.post("your authentication url to check if session exits ",{username:username}).subscribe(data=>{            if (data["loggedIn"] === false)               this.router.navigate(["/users/login"])        })           }}

Angular also has HTTP interceptors,you can solve this issue with jwt and http interceptors