1
00:00:00,930 --> 00:00:06,780
And once our bare bones setup is in place now, we simply want to go back to the controller, the main

2
00:00:06,780 --> 00:00:09,690
one, and we'll need to copy and paste these things.

3
00:00:09,810 --> 00:00:13,800
And again, I'm just doing this just so we can get through the functionality.

4
00:00:14,070 --> 00:00:21,420
And you're looking for JWT because, of course, we'll implement that functionality as well as the custom

5
00:00:21,420 --> 00:00:22,370
API here.

6
00:00:22,740 --> 00:00:25,080
And I said not in the following videos.

7
00:00:25,320 --> 00:00:27,320
We'll work on more hours.

8
00:00:27,540 --> 00:00:31,050
So essentially we'll create here more classes.

9
00:00:31,230 --> 00:00:33,920
So we'll have to do some refactoring as well.

10
00:00:34,080 --> 00:00:37,650
But for the time being, we'll just grab these two lines of code.

11
00:00:38,010 --> 00:00:39,840
We want to go back to the OTH.

12
00:00:40,170 --> 00:00:43,080
We want to make sure that the paths are correct.

13
00:00:43,360 --> 00:00:46,140
So as far as JSON Web token, of course it doesn't really matter.

14
00:00:46,410 --> 00:00:47,850
I mean, that's the package reinstalled.

15
00:00:48,060 --> 00:00:52,830
We just want to make sure that this path is correct and it looks about right.

16
00:00:53,100 --> 00:00:58,230
So now of course, let's go back to the controllers where it keeps crawling, keeps crawling.

17
00:00:58,530 --> 00:01:01,980
So of course that was the previous route, the login one.

18
00:01:02,370 --> 00:01:07,980
And as far as the dashboard, we simply want to take this logic where we're looking for the hattar.

19
00:01:08,220 --> 00:01:15,360
And if there's some kind of issue, course, we just throw the custom paper here, then we get the header.

20
00:01:15,570 --> 00:01:22,380
And if everything is great, if we can verify the token, then instead of setting up right away our

21
00:01:22,380 --> 00:01:29,340
response in our middleware, we're actually going to set up a property on request object and the property

22
00:01:29,340 --> 00:01:30,150
is going to be user.

23
00:01:30,480 --> 00:01:36,830
And then we'll pass it to the next model, which, of course is going to be this dashboard around.

24
00:01:37,170 --> 00:01:38,730
So let's go step by step.

25
00:01:39,060 --> 00:01:40,530
Let me take these.

26
00:01:40,980 --> 00:01:42,060
I mean, what is it?

27
00:01:42,060 --> 00:01:43,140
Five lines of code.

28
00:01:43,500 --> 00:01:44,150
Take it out.

29
00:01:44,160 --> 00:01:46,410
So everything up to try and catch you.

30
00:01:46,440 --> 00:01:51,450
When I go back to the OTH just now, you want to remove the console log.

31
00:01:52,300 --> 00:01:58,480
And just keep the next, because that is very, very important, then back in the controller, you also

32
00:01:58,480 --> 00:02:05,590
want to take the tri block, but you have to do a little bit of acrobatics here because I'll actually

33
00:02:05,590 --> 00:02:07,140
need of these lines of code.

34
00:02:07,510 --> 00:02:14,440
So let's go back over here, take the try catch as well, step by step and line, copy and paste.

35
00:02:14,740 --> 00:02:20,190
And here the logic is following where you want to remove this response with lucky number.

36
00:02:20,560 --> 00:02:27,420
So these things go, you want to cut it out and go back to your controller and set it up in the dashboard.

37
00:02:27,760 --> 00:02:29,590
So this logic stays, of course, the same.

38
00:02:29,890 --> 00:02:31,240
Why don't we have the lucky number?

39
00:02:31,240 --> 00:02:32,170
We generate that.

40
00:02:32,380 --> 00:02:36,760
And of course, we only send that response if we're successful.

41
00:02:37,150 --> 00:02:42,040
Now, back in the office, just like I said, we're still checking for the Hattar.

42
00:02:42,490 --> 00:02:44,500
We're checking whether it starts with bear.

43
00:02:44,740 --> 00:02:46,970
If not, we throw the customer appear.

44
00:02:47,290 --> 00:02:49,270
That's why we import it over here.

45
00:02:49,580 --> 00:02:53,860
Then we keep on scrolling, we get the split, we get the token.

46
00:02:54,070 --> 00:02:59,140
And of course, we have try and catch where we are invoking the verified method.

47
00:02:59,410 --> 00:03:03,670
We pass in a token that we're getting back as well as the second one.

48
00:03:04,090 --> 00:03:09,970
And then if we're successful, then instead of sending a response, since we're working in the middle

49
00:03:09,970 --> 00:03:14,410
where the logic is going to be following, where I'm going to go with CONSED, and then I'm looking

50
00:03:14,410 --> 00:03:15,130
for two things.

51
00:03:15,460 --> 00:03:21,150
I'm looking for ID and the user name here, and that one will be equal to the code.

52
00:03:21,490 --> 00:03:25,540
So of course if I'm successful, this is going to have some kind of value.

53
00:03:25,750 --> 00:03:27,400
If not, we'll throw the error.

54
00:03:27,760 --> 00:03:34,120
And then if that is the case, I want to go with a drug user and I'll just set it up to the object where

55
00:03:34,120 --> 00:03:42,020
I'll have ID and username and of course, once I have set up the user properly with this object value.

56
00:03:42,400 --> 00:03:44,340
Now, of course, I want to call mixed.

57
00:03:44,530 --> 00:03:47,470
So we'll move this next up over here.

58
00:03:47,830 --> 00:03:53,800
And what happens in the controller in the request will have that user property.

59
00:03:54,160 --> 00:03:58,330
And now, instead of looking for Decoded, of course, we'll look for user.

60
00:03:58,720 --> 00:04:05,260
Now in order to make it a bit more explicit, I'll actually consider it just so you can see where it's

61
00:04:05,260 --> 00:04:05,820
coming from.

62
00:04:06,070 --> 00:04:13,720
So I'm going to go here with Rick and User so you can clearly see that we're getting that from our middleware,

63
00:04:13,720 --> 00:04:14,110
of course.

64
00:04:14,440 --> 00:04:20,709
And instead of looking for Decoded, we're going to go here for user on user name.

65
00:04:21,040 --> 00:04:25,090
Now, in this case, I also need to direct since of course, I didn't need the structure.

66
00:04:25,270 --> 00:04:32,230
So on request object and I have the user property and in there I'll have the user name as well as I

67
00:04:32,890 --> 00:04:35,420
and was just start out one more time, the functionality.

68
00:04:35,710 --> 00:04:38,390
So again, I'm going to be on localhost 31.

69
00:04:38,590 --> 00:04:39,880
I don't have the token.

70
00:04:40,120 --> 00:04:46,330
So now of course I shouldn't see anything in the console and I don't because remember, we only get

71
00:04:46,330 --> 00:04:49,030
to the dashboard if we're authenticated.

72
00:04:49,420 --> 00:04:52,300
So let's try it out here somewhere else appear.

73
00:04:52,660 --> 00:04:56,720
And then again, my secret password, I'll submit, OK?

74
00:04:56,770 --> 00:05:02,940
I created the user tokens present and then once I click on getting the data now of course I have.

75
00:05:02,950 --> 00:05:03,610
Hello Peter.

76
00:05:03,880 --> 00:05:06,430
And I'm getting of the lucky number.

77
00:05:06,640 --> 00:05:12,250
And now if I take a look at the console, check it out now of course on request object.

78
00:05:12,520 --> 00:05:18,740
Once we get to the dashboard we actually have the user with Audi and user name here.

79
00:05:18,850 --> 00:05:25,810
And of course, this is coming from our middleware, where essentially, again, we check for the authorization

80
00:05:25,810 --> 00:05:26,110
letter.

81
00:05:26,380 --> 00:05:32,410
When we check for the bearer, we split it up, we get the token, then we use try and catch because

82
00:05:32,410 --> 00:05:37,780
we want to run the verify method and then we pass on the token, we pass in the secret.

83
00:05:38,050 --> 00:05:41,560
And then from the decoder we get the ID and username.

84
00:05:41,950 --> 00:05:47,950
And since we want to pass it to the next middleware, essentially we create a new object, which is

85
00:05:47,950 --> 00:05:52,390
a user object on the request and then pass it on to the next Minoa.

86
00:05:52,570 --> 00:06:00,100
And of course, if we're not able to verify the token, then we send back our custom API response.

87
00:06:00,110 --> 00:06:06,130
And again, the end result is following where you can set up whatever model or else you want.

88
00:06:06,490 --> 00:06:12,220
And in front of all of them, you can just take off Minola and then you don't have to repeat this code

89
00:06:12,400 --> 00:06:14,770
coder sitting in one place and check for token.

90
00:06:15,040 --> 00:06:18,700
If the token is not present, then you just send back the error response.

