Welcome back.
And this week we are going to sign in the user using email and password and therefore you can go ahead
and try to do yourself.
So just follow along the password authentication here in the firebase documentation.
And you can see that it's, um.
Yeah, they're using an extra variable here, which is called off in order to have the firebase of system
once and not having to recreate it every single time you want to do something with it.
But as we are just using it once when signing in, it's actually find a way we do it, but both ways
are fine.
So you can, of course, go ahead and create a late initialized variable called Firebase all or just
all, and then use that.
So you need to initialize it.
At one point, of course, you get the firebase all instant and then you can go ahead and use this code
here in order to sign in the email with the user, with an email and a password or so.
Please try to do that, try to implement the Sinon feature in this sign an activity.
All right, so this time I'm going to just follow along here.
I'm just going to use the documentation to create this new light and variable and we need to go to our
sign in activity, so.
And here, activities and and, uh, sign in activity, then we need to create this plate in a variable
that we want to initialize later on.
So we need to import firebase authentication and then so we can either set off in uncreate or we can
do it at the moment when we actually use the function.
So either way is fine, I think just doing it here is going to be fine as well.
So let's just said the get instant's here.
Why those all get instance, all right, and now we, of course, need to have a function which allows
us to sign in.
So how do we want to call it?
Well, I'm just going to call it sign in.
Registered user, so private fund sign in registered user, you could, of course, just call it sign
and user, that would be fine as well.
So now let's go back and check the code here.
So it says Volle, current user of current user check if user is signed in.
So this is how you can check.
If these are signed, then we will do that later on.
But what's important is this part here.
So where we sign in the user with email and password.
So first of all, of course, we need to have the email and password, so VUL e-mail string that will
be ETTY email, text to string and then we trem as well.
So actually it's the same as we had it in the sign up functionality.
So here we only need email and password.
So let's just copy those two over to our sign and activity because they are really just the same with
just trimming an empty space at the end.
Then we need to validate the form and we're going to validate it in a very similar way as we've done
here.
So private fund, validate form.
Let's just copy that and use it in our sign in activity as well.
So here I'm just going to create one.
But the difference is that I'm going to not use the name here.
So when signing in, we just need to email and password, right.
So we don't need to have the user name as well.
And here, of course, we can then get rid of this whole part here.
And also, we need to make sure that our class is inheriting from base activity because in base activity,
that's where we set up everything that we can now use for the snack bar.
So show our snack bar is what we prepared in our base activity and now we can reuse it here.
So now we have validated for.
OK, so at this point we can validate the form with the email and password that we have from the user.
So if email and password are validated, so validate form with email and password, if that is true,
then we want to sign in the user.
So invalidate form.
We just checked if the user has entered anything at all, if it's empty, then we just want to let him
know, hey, you need to enter something.
But otherwise we're going to be fine with whatever he has entered and then we can do the authentication.
Of course, we can also first show the progress dialogue where we just let the user know, hey, please
wait.
So actually it's going to be the same as and sign up.
And it's a little more because we also need to get the resources, get string and so forth, so let's
do the same thing here and it's almost the same function.
So the Sinon registered users almost or Disvalue they form, actually, it's almost the same function
as our sign up, but slightly different still.
OK, now we need to make sure that email is the right one because it is the one from sign ups.
So we need to make sure that it's the one from sign in.
So any email we can see we have to hear.
So now what we can do is we can rename one of them.
So let's rename the one from our sign up or actually let's go for the one inside.
And I think that makes more sense.
So.
Here it's on our resources lay out sign in and here to Ed, text's are the ones that we are interested
in, right?
So.
Text fields lay out here, eat email on the score, Sinon, and then.
ET password on the score, sign it.
So how I'm going to call them.
All right.
Of course, you could use sign on the score in to be more precise, so that.
It's even happier here, just like that.
OK, so now inside and we need to make sure that it's E.T. email, sign in and password sign it, OK,
because otherwise we will use the one from sign up.
OK, so at this point we can go ahead and run our code.
So here we can now finally run the code from the website.
So let's copy this.
And then added in here.
OK, so I'll tell you why I'm not going to use that log.
Well, we can.
His dad can import it.
We don't have a tag yet.
That's also something that we might want to import, so import toast update wise, what we're going
to use.
So here they have tag as well.
So I'm just going to call this tag sign in.
And here as well, sign an.
Also, by the way, this vile user of current user.
Well, that's fine, but we're not using it right now, so we don't need it yet.
And also here we say authentication failed, but, well, we are providing the exception in the Lochhead,
so I think that's going to be fine.
OK, so this is very similar to what we had before in our sign up here.
Of course, we could also, instead of toasting the whole error message to the user, which he doesn't
understand probably, or which doesn't make sense to him, we could replace that, of course, with
also registration failed or something like that.
So let's just do that real quick here.
Registration failed.
All right, so now we can go ahead and test it, so let's see if we can sign in our user.
Once we click the button, but of course, we still need to fix the error that we have here.
So as it seems, I'm liking one curly bracket at one point when I copy to validate form, I didn't copy
it correctly.
Also, something that we probably should also do is hide our progress dialogue at one point because
here we show it and if we don't hide it, then it's not going to be very good.
Look at your app, so let's hide it directly here.
So once it's completed, so high progress, dialogue and then.
Let's move over to our main activity, OK, just so that we see that it actually works.
So start activity, intent from this to the main activity, colon, colon, class, Java.
And intent needs to be important.
Let's do that real quick.
OK, so once we are successfully signed, then we want to move over to our main activity here.
Now, of course, there's one last thing to do, and that is to add functionality to the button, because
currently when we sign in, when we click on the sign in button activity, sign in.
So let's see, we have this button called button sign in.
If we clicked this one, nothing happened.
So let's add an unclipped listen to it sign in said on Click Listener.
And here we will use to sign in registered user function functio.
So this functionality just prepare.
All right, and then there's one bug that I found as well when running the application so you can test
it, run it.
The thing is, our set up action bar is really just a copy of the setup action bar and the sign up activity.
And when you do that, you have to be careful.
And I wasn't careful enough.
So you can see set up said support action bar for toolbar sign up activity.
Of course, it should be for our toolbar sign in activity.
And the same goes down here with the set navigation on Click Listener.
So if you do these kind of things, copy and pasting, you always need to double check for changes.
But at the point when you test it, that's latest word, the latest moment when you realize those things.
So no worries there.
It's still fine.
So let's run it again.
Now, we should hopefully get to design the activity.
All right, so there we are.
OK, so this seems to work.
Let's test Dennis at.
Gmail dot com password was super secure, sign in, please wait.
And we are moved over to the hello world screen, which is our main activity, so as it seems, this
worked.
So we are now logged in, which is pretty cool.
So now you can see how you can sign up a user and how you can sign in a user.
And now we can go ahead and display stuff to the user that is relevant to him.
So that's, of course, what we have to set up step by step, because there is a lot of functionality
that will follow and we haven't even touched the database yet.
So that's super interesting stuff that we're going to look at later on.
So in the next video, first of all, we are going to create a new entry in the database.
So we're going to create a new database itself.
Right.
So using the firestorm and the next video and then we're going to use the user class.
So we're going to create a new model and so forth.
So let's go ahead and check that out.
See you in the next one.
And by the way, I hope you were successful in writing this code and you fixed the box that we have
here and everything, because at that point, I would expect you to be able to do that.
So if you weren't able to do that, then try to do and we'll create another app where you do the sign
in and sign up functionality from scratch all by yourself using the documentation only because this
is going to be super relevant and important when it comes to developing applications for customers in
the future or even for your own ideas that you have.
Because running into errors is normal.
It's no problem.
Running to bugs is also normal.
It's important to fix them.
It's important to check out documentations, to read through the Internet, to find solutions and so
forth.
All right.
See you in the next one.