1
00:00:00,080 --> 00:00:02,360
We're pretty much done with the registered user.

2
00:00:02,360 --> 00:00:05,140
And up next, let's work on login user.

3
00:00:05,150 --> 00:00:07,550
And in this case, we'll do a little bit differently.

4
00:00:07,550 --> 00:00:10,790
We'll start with validate login input.

5
00:00:10,790 --> 00:00:18,020
So we will validate the values that are coming in and then we'll set up the functionality As far as

6
00:00:18,020 --> 00:00:19,640
what are we looking for?

7
00:00:19,640 --> 00:00:21,680
Well, let's just navigate to.

8
00:00:22,290 --> 00:00:23,340
Complete the application.

9
00:00:23,340 --> 00:00:30,030
So notice this is what we are expecting for register, and if I click on login, we only are looking

10
00:00:30,030 --> 00:00:36,690
for email and password and that's why in the Readme you'll find this Json and you want to add it to

11
00:00:36,690 --> 00:00:37,530
the login one.

12
00:00:37,530 --> 00:00:39,690
So let's navigate to login user.

13
00:00:39,690 --> 00:00:46,140
Again, same deal, it's in the body and for now if I send it, of course I still get back 200.

14
00:00:46,140 --> 00:00:53,670
So now let's set up that validation middleware for these two values and this is going to be extremely

15
00:00:53,670 --> 00:00:56,190
similar to what we have over here.

16
00:00:56,190 --> 00:01:03,030
And if you really want to save some time, of course you can just copy and paste, but make sure that

17
00:01:03,030 --> 00:01:04,860
you remove some checks.

18
00:01:04,860 --> 00:01:09,540
For example, when you're logging in, you're not looking for unique email.

19
00:01:09,690 --> 00:01:11,130
I mean, that's not going to make sense.

20
00:01:11,130 --> 00:01:12,300
I just registered.

21
00:01:12,330 --> 00:01:16,050
Of course, that email is going to be already in the database.

22
00:01:16,560 --> 00:01:21,970
And as far as the password, keep in mind that we'll be comparing the password anyway.

23
00:01:21,970 --> 00:01:27,520
So it doesn't really matter whether the user is providing a value that's less than eight.

24
00:01:27,550 --> 00:01:33,520
If that's the case, then the passwords will match anyway and he won't be able to log in.

25
00:01:33,520 --> 00:01:40,930
So long story short, let me just showcase how I would approach such a feature.

26
00:01:40,930 --> 00:01:44,800
First of all, we need to come up with the new name.

27
00:01:44,800 --> 00:01:49,240
I'm going to go with login and then let's go line by line.

28
00:01:49,240 --> 00:01:51,070
First of all, we don't need name.

29
00:01:51,400 --> 00:01:53,770
Of course, we're looking only for email.

30
00:01:54,620 --> 00:01:59,390
And for the email, I'll keep that empty on his email.

31
00:01:59,420 --> 00:02:02,280
But I will remove the custom one for the password.

32
00:02:02,300 --> 00:02:04,220
I'll remove the length.

33
00:02:04,220 --> 00:02:06,870
And also we're not looking for that location.

34
00:02:06,890 --> 00:02:07,490
Correct.

35
00:02:07,490 --> 00:02:12,170
So now let's navigate to auth router.

36
00:02:13,140 --> 00:02:15,570
Are looking for login one.

37
00:02:16,350 --> 00:02:24,190
So validate login input and then we want to stick it in front of the login controller.

38
00:02:24,190 --> 00:02:29,180
So this is going to be our middleware and then let's try it out with few values.

39
00:02:29,200 --> 00:02:37,150
So first let me send without a password and in this case I get an error, but it's not the error that

40
00:02:37,150 --> 00:02:38,150
I was expecting.

41
00:02:38,170 --> 00:02:45,250
Essentially, my syntax was incorrect, and if everything is correct, essentially we will have password

42
00:02:45,250 --> 00:02:46,390
is required.

43
00:02:46,390 --> 00:02:48,970
And of course the same deal with email.

44
00:02:48,970 --> 00:02:55,000
And yes, I know I already have said this quite a few times, but keep in mind that it's a common practice

45
00:02:55,000 --> 00:02:57,760
to check for empty values in both places.

46
00:02:58,530 --> 00:03:00,960
On a server as well as the front end.

47
00:03:00,960 --> 00:03:08,490
And if I don't provide email altogether, then I get this email as required and invalid email format.

48
00:03:08,520 --> 00:03:12,900
If there is an email, but for example, I just go with gmail.

49
00:03:12,900 --> 00:03:21,330
Then of course I'll have this error over here and with this in place now we can move on to a login controller

50
00:03:21,480 --> 00:03:26,790
and start looking for the user and comparing the passwords.

