How To Determine a User Status on an Ionic App
If you are looking for a solution to determine the login status on your app then you’ve come to the right place!
While developing a clients app, I needed to determine whether to display a Login or Logout option in the side menu.
First I tried to implement a global variable which updated on a user using the login and logout functions. This turned out to not always be reliable so I went to Google and searched for my problem instead.
I came across other developers mentioning a system in Ionic called Events. There are three instances to use with the Events system, Publish, Subscribe and Unsubscribe.
Publish - I used this when a user had successfully logged in or logged out.
Subscribe - I used this to ‘listen’ for the logged in or logged out event in the side menu where I needed to know the status of the user. I changed the value of a boolean variable to determine wether the user is logged in or not then placed an ngIf on the items in the view which show or hide depending on the boolean value of the variable.
Unsubscribe - I used this to to stop listening to an event.
You can find more about Events here in the Ionic Documentation - https://ionicframework.com/doc...< Back to Blogs
Umbraco Certified Expert, Gamer and burger demolishing machine. Planet Wide City’s longest serving Developer.