Hello, I have an app with a side menu and a user login. Each user has a role and each role has it’s own associated menus. The menus are loaded trough a REST API.
So far I’ve made it work somewhat by having checks in the app.component constructor and depending on the role it loads different menus, but this has the drawback of not updating after a user logs out and a user with a different role logs in - it keeps the loaded menus from the previous user.
this.storage.get('loggedIn')
.then((loggedIn) => {
this.loggedIn = loggedIn;
if (this.loggedIn) {
this.rootPage = 'HomePage';
this.storage.get('user')
.then((storage) => {
this.userService.getUser(storage.id)
.subscribe(user => {
this.loadMenus(user.role.toString(), ['role']);
})
});
} else {
this.rootPage = 'LoginPage';
}
this.initializeApp();
});
This is the code in my app.component constructor. loadMenus sets menus variable with the returned menus depending on role. I was thinking that I need to just set menus = [], but I don’t know where to do it.