Update Side Menu On Success Login


How do I update side menu on user success logged in? I need to display the current username on the side menu.

I need to reload the page to see it display correctly.

Side menu is disabled on user login page. It will enable again right after user logged in successfully and homepage pushed to nav.

take a look at the Ionic 2 Conference App and see how they use the this.loggedIn and the listenToLoginEvents(), so you can adapt to your needs.

1 Like

Yes… I have looked on that app and my app also from the modification of Ionic 2 Conference App.

Where should I put the event publish? On success logged in function or on load of homepage?
My app is communicate with API and JWT will be saved on local storage on user success logged in.

1 Like

you can use this.events.publish when the user make the login, so update a var with the username inside the listenToLoginEvents… then update the menu, like the conference app use to show logged in and logged out itens.



After read Events Documentation and your reply, I got an idea how to make it working. My API only returns token value on user logged in so I need to run another request to get user profile in object format.

publish event with userProfile object
this.events.publish('user:loggedIn', userProfile);

after that, on listenToLoginEvents
this.events.subscribe('user:loggedIn', (user) => { this.currentLoggedUser = user; });


Agradeço a esse post pois graças a vocês eu consegui resolver o problema.

Muito obrigado!