I have a app.component that manage a header with menu. The html of this component conditionally check if the variable "isAdmin" and "isAuthenticated" are true so can enable/disable every menu link.
When i login through an auth.component and auth.service i return to app.component the status of a user through an observable set in the ngOnInit interface implementation:
ngOnInit() {
this.isAuthSubscription = this.authService.isAuth$
.subscribe(
val => {
let role;
role = val
this.isAuthenticated = false;
if (role) {
this.isAuthenticated = true;
this.isAdmin = false;
if (role == 'admin'){
this.isAdmin = true;
}
}
this.user = this.helpService.getUser();
});
}
If i work inside the page everything works, but if i refresh the page pressing enter on the url bar of the browser i loose all information about "isAdmin" and "isAuthenticated".
Refreshing fires up a server http get method that i inserted to avoid 404 status response:
jAppRouter.get('/', function (req, res, next) {
res.render('index');
});
it probably depends that information come across the observable, but how can solve this problem? I basically want to be able to refresh my menu (app.component) from a different component, maybe this is not the right way... Thanks Max