1
00:00:00,180 --> 00:00:05,910
Beautiful, and our initial setup is going to look something like this where effectively we want to

2
00:00:05,910 --> 00:00:07,140
set up another middle where.

3
00:00:08,000 --> 00:00:15,470
So the end result is going to be that for certain routes before we can access throughout, as an example

4
00:00:15,650 --> 00:00:20,360
of that user, there's going to be a middleware that checks for that token.

5
00:00:21,050 --> 00:00:27,650
So if the token is not power or it's not present, then we'll send back the error.

6
00:00:27,870 --> 00:00:32,119
And like I said, we will log out the user on a frontend as well.

7
00:00:32,479 --> 00:00:34,250
Now what do we want to do?

8
00:00:34,280 --> 00:00:38,850
Well, we want to create off jurors or authenticate jurors in middleware.

9
00:00:38,870 --> 00:00:44,180
Marcus, I'm going to go with off because authenticate is another dewji that I have trouble spelling

10
00:00:44,510 --> 00:00:45,560
and writing.

11
00:00:45,950 --> 00:00:49,910
And then inside of the off drafts, I want to create a function.

12
00:00:50,090 --> 00:00:51,020
I'll call it off.

13
00:00:51,320 --> 00:00:52,340
I'm going to go with async.

14
00:00:52,550 --> 00:00:57,170
Remember, we're still accessing Rackauckas and next, and this is very important.

15
00:00:57,170 --> 00:01:02,780
So we're passing it on to a next middleware, which in our case is of the controller.

16
00:01:03,110 --> 00:01:04,910
And for timing, we just want to console.log.

17
00:01:05,330 --> 00:01:09,470
We want to console.log whether everything works, we want to export as default.

18
00:01:09,470 --> 00:01:15,110
And now in this case, I will call this authenticate user because it just makes a little bit more sense

19
00:01:15,110 --> 00:01:15,440
to me.

20
00:01:15,920 --> 00:01:21,920
And essentially, we want to import that in the author out and we'll stick it in front of the update

21
00:01:21,920 --> 00:01:22,340
user.

22
00:01:22,730 --> 00:01:29,270
So please keep in mind logged in the register are still public roads, but this is going to be a private

23
00:01:29,270 --> 00:01:29,570
route.

24
00:01:30,440 --> 00:01:39,110
Where we will check for that user and then when it comes to jobs, like I just said, all of the routes

25
00:01:39,260 --> 00:01:45,800
will be restricted and essentially we have two options either you can do that in server gas.

26
00:01:45,800 --> 00:01:52,340
So we import authenticate user and then just place it in front of the jobs router.

27
00:01:52,640 --> 00:01:57,830
So that means that each and every request about goes to ports, large jobs.

28
00:01:58,220 --> 00:02:05,210
We'll have that authentication or you can go to jobs zones and then do that manually.

29
00:02:05,690 --> 00:02:08,000
So in this case, I'm just showcasing one.

30
00:02:08,210 --> 00:02:09,830
The show starts one.

31
00:02:10,070 --> 00:02:13,850
But keep in mind, you need to add that to each and every route.

32
00:02:14,420 --> 00:02:19,820
Now, in this case, I think I'm going to go with this option where essentially I'll stick the authenticate

33
00:02:19,820 --> 00:02:20,940
user in front of jobs.

34
00:02:21,830 --> 00:02:26,150
But to tell you, honestly, it is actually my preference to do that in the world.

35
00:02:26,150 --> 00:02:31,100
Since that way, I can clearly see which routes have that restricted access.

36
00:02:31,370 --> 00:02:35,600
And keep in mind that if you're going to have a setup where authenticate user.

37
00:02:36,620 --> 00:02:38,670
Is not applied to all the.

38
00:02:39,020 --> 00:02:44,120
Well, then you don't have two options and you literally have only one option where we have to go to

39
00:02:44,120 --> 00:02:50,960
the house, one import the main law and then choose their out you want to authenticate.

40
00:02:51,320 --> 00:02:52,310
Hopefully that is clear.

41
00:02:52,580 --> 00:02:54,680
So now let's get cracking.

42
00:02:55,160 --> 00:02:57,890
And first we want to go to Manila folder.

43
00:02:58,180 --> 00:03:03,140
I don't think I said I'm going to go with off an address now instead of the office.

44
00:03:03,150 --> 00:03:03,590
Yes.

45
00:03:04,010 --> 00:03:04,670
What do we want to do?

46
00:03:04,700 --> 00:03:06,890
Well, we want to set up that function, correct accounts.

47
00:03:07,280 --> 00:03:10,160
It's going to be equal to an all online.

48
00:03:10,190 --> 00:03:11,480
It's going to be a cinch.

49
00:03:12,230 --> 00:03:17,720
And we're looking for rec and rice and a next round inside of the function body.

50
00:03:17,720 --> 00:03:26,060
Let's go with console.log and then authenticate and user and then let's remember to go with next webwise.

51
00:03:26,330 --> 00:03:33,710
The user will be hearing we want to go with export and then default to export default, and then I'm

52
00:03:33,710 --> 00:03:34,610
looking for off.

53
00:03:35,240 --> 00:03:38,900
And let's start, I guess, with a crossroads.

54
00:03:39,770 --> 00:03:41,150
So I'm going to navigate over here.

55
00:03:41,510 --> 00:03:47,660
I want to import that from where, well, I'm going to be looking for the off middleware, correct?

56
00:03:48,050 --> 00:03:57,230
So let's just go here and let's say that the name will be authenticate user and ticket and then user.

57
00:03:58,250 --> 00:04:04,250
And once we have that one in place, then we'll go with from and now we're looking for the middleware.

58
00:04:04,550 --> 00:04:09,290
And then more specifically off, hopefully this one is spelt correctly.

59
00:04:09,290 --> 00:04:13,130
I mean, I don't see the Blue Squiggly Line, so what's my right?

60
00:04:13,130 --> 00:04:16,160
And then like I said, these two are still public.

61
00:04:16,790 --> 00:04:21,540
I mean, anyone should have ability to register and log it correct.

62
00:04:21,829 --> 00:04:29,510
However, once we want to update the user, this is going to be restricted to authenticate user like

63
00:04:29,510 --> 00:04:29,750
so.

64
00:04:30,140 --> 00:04:38,930
So let's go here and then let's say authenticate and then user, let's save this and I'll do the same

65
00:04:38,930 --> 00:04:40,490
thing in the jobs one.

66
00:04:40,910 --> 00:04:41,960
So copy of this one?

67
00:04:42,530 --> 00:04:46,490
I mean, there's no point to retype the import one more time.

68
00:04:46,970 --> 00:04:50,260
And or you're not sorry, I'm not going to go this route.

69
00:04:50,270 --> 00:04:52,310
I'm not going to add to each and every one of them.

70
00:04:52,610 --> 00:04:53,250
My apologies.

71
00:04:53,270 --> 00:04:59,900
Actually, I want to remove it, and let's navigate to the server now since the middleware is in the

72
00:04:59,900 --> 00:05:00,980
same path.

73
00:05:01,400 --> 00:05:02,450
Well, let's do this.

74
00:05:02,450 --> 00:05:06,440
So I'm going to go with authenticate user, but we're not going to levels up.

75
00:05:06,950 --> 00:05:12,860
Remember, now we are in the server, so the path is a little bit different than let's keep on scrolling

76
00:05:12,860 --> 00:05:18,650
and where we have this one over here, let's just go with authenticate and user.

77
00:05:18,830 --> 00:05:21,560
So that is the name I'm going to go with comma.

78
00:05:21,920 --> 00:05:25,820
And once we have everything in place, I think there's something missing.

79
00:05:26,210 --> 00:05:29,080
The fact is that I don't have Jess.

80
00:05:29,090 --> 00:05:29,750
My apologies.

81
00:05:30,110 --> 00:05:33,560
So let me go back to the answers as well.

82
00:05:34,070 --> 00:05:39,350
Otherwise, we know that we're going to get about Dewji, where essentially we need to add that extension.

83
00:05:39,590 --> 00:05:40,520
I've got a double check up.

84
00:05:40,820 --> 00:05:43,940
There was actually errors, and now everything works.

85
00:05:44,270 --> 00:05:52,610
So now just go to a postman and test it out, where if I go with update user or any of the jobs ones

86
00:05:52,910 --> 00:05:57,740
I should see in a console that I should see authenticate user.

87
00:05:57,800 --> 00:06:01,580
So let's try it out and navigate to the postman have log in.

88
00:06:01,790 --> 00:06:03,260
And I just thought, OK, that's awesome.

89
00:06:03,630 --> 00:06:06,740
But I want to go with update user now.

90
00:06:06,890 --> 00:06:11,840
I think, I mean, I'm not going to pass anything and we're just going to send it, and I have the update

91
00:06:11,840 --> 00:06:12,470
user string.

92
00:06:12,800 --> 00:06:13,550
So that's cool.

93
00:06:13,940 --> 00:06:21,500
But what I'm really looking for is a vest for I can see a string that means that now every request that

94
00:06:21,500 --> 00:06:25,490
goes to a user, it's going through this middleware.

95
00:06:25,490 --> 00:06:28,520
Correct, and the same deal is going to be over here in jobs.

96
00:06:28,820 --> 00:06:33,800
Now, I'm not going to do with all of the jobs, but I'm just going to get one and the same deal that

97
00:06:33,800 --> 00:06:36,890
I have authenticate user and notice the request.

98
00:06:37,250 --> 00:06:40,580
And this is going to be our initial user authentication setup.

