We're pretty much done with the registered user.
And up next, let's work on login user.
And in this case, we'll do a little bit differently.
We'll start with validate login input.
So we will validate the values that are coming in and then we'll set up the functionality As far as
what are we looking for?
Well, let's just navigate to.
Complete the application.
So notice this is what we are expecting for register, and if I click on login, we only are looking
for email and password and that's why in the Readme you'll find this Json and you want to add it to
the login one.
So let's navigate to login user.
Again, same deal, it's in the body and for now if I send it, of course I still get back 200.
So now let's set up that validation middleware for these two values and this is going to be extremely
similar to what we have over here.
And if you really want to save some time, of course you can just copy and paste, but make sure that
you remove some checks.
For example, when you're logging in, you're not looking for unique email.
I mean, that's not going to make sense.
I just registered.
Of course, that email is going to be already in the database.
And as far as the password, keep in mind that we'll be comparing the password anyway.
So it doesn't really matter whether the user is providing a value that's less than eight.
If that's the case, then the passwords will match anyway and he won't be able to log in.
So long story short, let me just showcase how I would approach such a feature.
First of all, we need to come up with the new name.
I'm going to go with login and then let's go line by line.
First of all, we don't need name.
Of course, we're looking only for email.
And for the email, I'll keep that empty on his email.
But I will remove the custom one for the password.
I'll remove the length.
And also we're not looking for that location.
Correct.
So now let's navigate to auth router.
Are looking for login one.
So validate login input and then we want to stick it in front of the login controller.
So this is going to be our middleware and then let's try it out with few values.
So first let me send without a password and in this case I get an error, but it's not the error that
I was expecting.
Essentially, my syntax was incorrect, and if everything is correct, essentially we will have password
is required.
And of course the same deal with email.
And yes, I know I already have said this quite a few times, but keep in mind that it's a common practice
to check for empty values in both places.
On a server as well as the front end.
And if I don't provide email altogether, then I get this email as required and invalid email format.
If there is an email, but for example, I just go with gmail.
Then of course I'll have this error over here and with this in place now we can move on to a login controller
and start looking for the user and comparing the passwords.