1
00:00:00,330 --> 00:00:06,300
Beautiful once we can successfully registered the user now, of course, let's worry about the login

2
00:00:06,300 --> 00:00:14,190
functionality and die honestly, we have covered pretty much all of the things apart from checking the

3
00:00:14,190 --> 00:00:14,760
password.

4
00:00:15,150 --> 00:00:20,490
So, of course, since we're using a library to hash the password, of course, we want to compare it

5
00:00:20,490 --> 00:00:21,050
as well.

6
00:00:21,570 --> 00:00:28,140
Now, since that involves creating another instance, method will actually do that in NextRadio in this

7
00:00:28,140 --> 00:00:28,590
video.

8
00:00:28,830 --> 00:00:32,700
Simply want to check whether we are getting the email and the password.

9
00:00:33,150 --> 00:00:36,870
We get some kind of values because that's the whole setup for waterlogging.

10
00:00:36,930 --> 00:00:39,690
In this case, they don't need to provide name.

11
00:00:39,840 --> 00:00:41,850
They just need to provide email and a password.

12
00:00:42,240 --> 00:00:44,760
If they don't, we send back the bad request.

13
00:00:44,760 --> 00:00:48,500
One after that will check for the user in our database.

14
00:00:48,750 --> 00:00:53,070
So basically we'll go with our user and find one and we'll pass in the email.

15
00:00:53,520 --> 00:00:57,720
And if we can find one, then of course we'll send back the user.

16
00:00:58,080 --> 00:01:01,200
And if not, then of course we'll send back another error.

17
00:01:01,560 --> 00:01:03,000
And let's start here.

18
00:01:03,930 --> 00:01:11,190
By removing that or not sand, I'll close the sidebar here and let's start by email and password.

19
00:01:11,430 --> 00:01:17,850
And this is the case where I'll do the checking, the initial checking right in the controller and I'll

20
00:01:17,850 --> 00:01:24,780
actually cover why that's my preference in this case once we're done setting up COMPAR passwords functionality.

21
00:01:24,970 --> 00:01:31,950
So first in the request, I'm looking for email and password and right out of the gate I'll say if no

22
00:01:31,950 --> 00:01:39,030
email or if no password, then of course we'll go with our bad request.

23
00:01:39,240 --> 00:01:43,950
And of course we'll do that in a block and we'll say throw you.

24
00:01:44,220 --> 00:01:46,680
And we already have the import format request.

25
00:01:46,980 --> 00:01:50,850
So we just go with that request error and we just need to provide a message.

26
00:01:51,090 --> 00:01:55,740
Please provide email and password.

27
00:01:56,630 --> 00:02:01,360
And once I have this one in place, then, of course, we want to check for the user, correct.

28
00:02:01,580 --> 00:02:02,660
How do we check for user?

29
00:02:02,690 --> 00:02:04,400
Well, we have the model.

30
00:02:04,640 --> 00:02:05,720
We have the user model.

31
00:02:05,960 --> 00:02:09,180
And on it we have a method by the name of find one.

32
00:02:09,500 --> 00:02:11,630
So let's come up with some kind of variable name.

33
00:02:11,630 --> 00:02:14,810
And my guess is going to be user and we'll go with a wait.

34
00:02:15,140 --> 00:02:20,480
Of course, it is synchronous and we go with user dot and find one.

35
00:02:21,310 --> 00:02:27,340
And then instead of passing in the area and all that will pass in the email, so whatever we're getting

36
00:02:27,340 --> 00:02:29,710
from the user, we'll just pass it in here.

37
00:02:30,100 --> 00:02:35,600
And effectively at this point, we have two options if the user exists.

38
00:02:35,940 --> 00:02:36,520
Awesome.

39
00:02:36,990 --> 00:02:42,820
And of course, we can send back the response with the username as well as we can create a token, of

40
00:02:42,820 --> 00:02:43,150
course.

41
00:02:43,630 --> 00:02:48,300
Now, if the user doesn't exist, then of course, we want to throw another error.

42
00:02:48,610 --> 00:02:54,340
Now, in this case, though, we're not going to be throwing by request requestor in this case if there

43
00:02:54,340 --> 00:02:55,210
is no user.

44
00:02:55,430 --> 00:03:03,430
And of course, we'll send back the unauthenticated error, because in this case, the user is not providing

45
00:03:03,430 --> 00:03:06,360
valid credentials and that's a big difference.

46
00:03:06,700 --> 00:03:08,040
So let's go back to Arthur.

47
00:03:08,080 --> 00:03:09,670
Yes, of course, we want to import that.

48
00:03:10,000 --> 00:03:13,530
So in here, let's go with on authenticated error.

49
00:03:13,900 --> 00:03:15,600
That's the class we're looking for.

50
00:03:15,850 --> 00:03:17,520
And here, let's check.

51
00:03:17,530 --> 00:03:22,920
And eventually there's also going to be code for comparing the password.

52
00:03:23,320 --> 00:03:25,720
But like I said, we'll do that in the next video.

53
00:03:25,870 --> 00:03:27,250
So that is still coming up.

54
00:03:27,580 --> 00:03:34,360
But I we'll just say if there is no user, then please throw that error thrown you.

55
00:03:34,630 --> 00:03:42,010
And again, we're looking for our Arth error and will simply say invalid credentials, credentials.

56
00:03:42,280 --> 00:03:48,100
And once we have taken care of this now, of course, we want to create the token, because if we go

57
00:03:48,100 --> 00:03:52,360
past this error, that means that user is their user exists.

58
00:03:52,690 --> 00:03:58,840
And remember the instance method we created in the previous videos of the create token one or create

59
00:03:58,850 --> 00:04:00,730
JWT don't remember.

60
00:04:00,730 --> 00:04:06,790
I believe it was created JWT because we want to invoke it and essentially we want to send back the same

61
00:04:06,790 --> 00:04:07,270
response.

62
00:04:07,630 --> 00:04:11,980
So the same response as we sent when we registered the user.

63
00:04:12,160 --> 00:04:19,990
So if a user exists, let's create a token and of course we'll go with user create JWT.

64
00:04:20,290 --> 00:04:23,860
We invoke it, we get back to token and now it's the same deal.

65
00:04:24,070 --> 00:04:25,390
We go with status.

66
00:04:25,630 --> 00:04:30,070
Now, in this case, we want to go with status codes and it's not going to be tier one.

67
00:04:30,310 --> 00:04:31,390
It's going to be two hundred.

68
00:04:31,600 --> 00:04:35,770
And of course, that one is the OK one and not as far as the JSON.

69
00:04:35,990 --> 00:04:36,870
Same deal.

70
00:04:37,210 --> 00:04:43,030
Also in my setup on my front end, I'm looking for the name property.

71
00:04:43,150 --> 00:04:49,630
So not to be redundant, but you always want to send back the token, but optionally you want to include

72
00:04:49,630 --> 00:04:50,950
some more things as well.

73
00:04:51,190 --> 00:04:54,950
And in my case, those more things is just a username.

74
00:04:55,240 --> 00:05:01,450
So go with user for name, of course the property and the user name and comma.

75
00:05:01,840 --> 00:05:04,810
And of course in here we're looking for a token.

76
00:05:05,320 --> 00:05:07,660
So right after the name will go token.

77
00:05:07,870 --> 00:05:13,290
And of course that is equal to the token that we're getting back from create token.

78
00:05:13,630 --> 00:05:17,800
And now of course, we can go and check it out in the postman.

79
00:05:18,340 --> 00:05:20,110
So let's go back over here.

80
00:05:20,350 --> 00:05:23,980
I believe we just created Peter twenty three.

81
00:05:24,430 --> 00:05:26,020
So now it's just the drought.

82
00:05:26,380 --> 00:05:28,090
I'll create a new drought.

83
00:05:28,480 --> 00:05:29,970
So it's a year in, year out.

84
00:05:30,250 --> 00:05:32,590
It's still going to be a postcard, of course.

85
00:05:32,950 --> 00:05:39,820
And as far as the URL, again, we're looking for our global variable forward slash and it's going to

86
00:05:39,820 --> 00:05:40,450
be auth.

87
00:05:40,780 --> 00:05:43,630
And of course, in this case, it's a logging one.

88
00:05:44,020 --> 00:05:46,270
And then let's just grab these values over here.

89
00:05:46,930 --> 00:05:51,670
Let's say that we'll take the name email as well as the password.

90
00:05:51,670 --> 00:05:57,700
And of course, we won't use the name, but we can nicely copy and paste just to save a little bit of

91
00:05:57,700 --> 00:06:03,040
time, copy and paste and of course, forgot about my curlers.

92
00:06:03,400 --> 00:06:05,260
So it placed it here properly.

93
00:06:05,260 --> 00:06:05,740
Everything.

94
00:06:07,080 --> 00:06:13,560
And this is turning out to be a mess, set up everything correctly over here, and I don't need the

95
00:06:13,560 --> 00:06:20,100
name and I'm just going to be sending the Peter twenty three with a secret again, for the time being,

96
00:06:20,100 --> 00:06:23,370
we're really just checking whether that secret is there.

97
00:06:23,650 --> 00:06:28,740
I'll say it and I'll say in the jobs one and I'll say login user.

98
00:06:31,030 --> 00:06:38,320
And what's the throughout her show here still have the Borias, everything is correct and of course,

99
00:06:38,320 --> 00:06:40,450
I'm getting back to Peter now.

100
00:06:40,450 --> 00:06:47,500
If I'll do some stakes, if, for example, our remove the password, we should get the four hundred

101
00:06:47,500 --> 00:06:50,600
one and that's the please provide email and password.

102
00:06:50,630 --> 00:06:51,490
OK, that's good.

103
00:06:52,060 --> 00:06:58,840
Me and the password and now it's messed up the email instead of twenty three I'll go to and now of course

104
00:06:58,840 --> 00:07:03,790
I have invalid credentials and of course the error in this case is four one.

105
00:07:04,120 --> 00:07:07,230
So our base functionality works really great.

106
00:07:07,630 --> 00:07:13,870
The only thing that's left to do in here is just to compare the password using our library.

107
00:07:14,170 --> 00:07:19,020
And if you remember the library name was B Creped James.

