Ionic 4: todo App + firebase
Lección 22 de 38 · 22 Checking User Login Status Building Mobile Apps with Ionic · Personas y blogs
22 Checking User Login Status Building Mobile Apps with Ionic
in this lesson we are going to learn how we can check if a user is already logged into the application or not in a real application you may not want the user to
be presented with a login page if they are already logged into the application so before you present the user with a login page you might want to check if the user is already logged into the
application or not and firebase allows you to do that when a user is logged into the application using the firebase SDK the information about the currently logged in user is stored locally on the
device in this case the browser and when the user reopens the application you can check this information and if the information looks good you can consider that the user is already logged in and
grant them access with firebase authentication and firebase SDK this is very easy to implement so let's see how we can do this so here we are back inside Visual Studio code and what I
want to do is as soon as this page is loaded we want to check if a user is logged in or not so inside the ng on init:function which is executed when this login page
is completely initialized we will use the firebase SDK so the squared and type in firebase dot off and on this you can use the function on earth state changed this function returns you a user if a
user is currently logged into the application otherwise it returns you null so for now we can just block this user object to the console and see what we get
and you can see that as the application refreshes in the browser I get this object logged to the console which contains the information about the user that I'm currently logged in with
however you can see that I have not entered my email and password to log into the application so this confirms that a user exists in the session and we can consider this user that we have all
this information for as the currently logged in user so in an ideal application if the user object here that we are logging to the console is not null in that case you may
want to navigate the user to the application otherwise you may want to take them to the login page so now that we know about signing up users logging them in and finding if a user is
currently logged into the application using firebase authentication in the next video we'll get started with cloud for a store and we'll learn how we can save data to cloud file store