Welcome back and this video, we are going to see how we can lock in the user automatically and send
him directly to the main activity instead of showing him the login screen once again.
And that is going to be based on whether there is a user ID for the current user.
So Firebase takes care of that automatically.
That's the power here.
We don't need to do that ourselves.
So we don't need you to download a token and then the token somewhere and all of those kind of things.
But the token is generated in the backend.
So it's generated on the firebase side.
So we don't need to do that sort of powers here.
Or what makes it easier for us is that we can just check if there is an instance for the current user
and then we can either get the user ID or we will just return an empty string and we can then use that
in order to either log in the user directly and send him directly to the main activity.
Or we can just send him to the login activity or the intro activity that we have here where he can then
decide to either register or log in.
OK, so let's go ahead and build the code for that.
So first of all, what I'm going to do is I'm going to pretty much copy this code here.
And store it in a variable, which I'm going to call current user, which will be Firebase get instant's
current user, so we will use that in order to then check if the current user is null or not, because
this can return null.
And if it does return now, it means that there is no current user.
All right.
So let's go ahead and create a helper variable, which will then be the one that we will return.
So I will show you what I mean in a second.
So this will check if the current user is not null, because if that's the case, then go ahead and
assign.
The current user I.D., the value of the current user thought you ID, so you maybe remember how we
used you ID here just a second ago and we had to force it, as you can see, so we had to force it with
the double exclamation mark.
But now we don't need to do that because we check if it's empty or not.
So this time we just get the current user and if the current user is empty, then we will return an
empty string.
So we would just say, well, actually, we don't even need to do that because it's going to be empty
anyways.
Right.
So now we can go ahead and return whatever current user ideas, because at that point it's either going
to be an empty string or it's going to be the unique user ID, which we then, of course, can use in
order to download the right information about the user, such as the boards that he has, the tasks
that are assigned to him, and all of the user information that we have about him.
Now, of course, where we want to do the sending over, so the.
Activity intent is in our interest to you.
So here is where we want to send the user either to the intro activity or to our main activity and then
the main activity in the end, we want to have all of the different boards and everything.
All right.
So here what we have is the splash activity.
So we don't want to go to the intro.
We want to go to splash here.
We had this little handle, right.
And we postulate started an activity and sent the user to the intro activity.
But now what we're going to do is we are going to.
Check if the current user I.D., so here, current user ID, I'm going to give it the same name and
here we take the first class and get the current user I.D..
So this will either be an empty string or it will be the user ID.
So the Joujou ID that is stored in the backpack and.
So this number here.
All right, so here we can then check if current user I.D. is not empty, all right?
Because if it's not empty, we know that we have a user that is locked in.
So what we can do is we can send them directly to the main activity in which we then will display,
for example, the.
Right.
And then if we don't have a user ID, so if it's empty, then we want to send them to the interactivity
where he can then choose to either register or log in or sign it.
OK, so that is pretty much it.
That's our splash activity.
Now it will take care of everything.
It will send us over to the right activity within two point five seconds.
So now let's test it and see if our application will directly send us to this activity instead of sending
us to the login activity or the interactivity.
All right.
So there we are approaching Menasche and we were sent directly to the main activity.
All right.
So this means that we are still logged in.
And, of course, we would need a log out button to allow the user to log out.
But we will add all of those features later on.
OK, so that was it for this video.
See you in the next one.