1
00:00:00,020 --> 00:00:00,340
All right.

2
00:00:00,350 --> 00:00:03,890
And once the authenticate user middleware is in place.

3
00:00:03,920 --> 00:00:10,700
Now let's use the user ID to get only the jobs that belong to a specific user.

4
00:00:10,790 --> 00:00:18,800
And also, when we create the job, we provide the created by property which we set up at the very beginning

5
00:00:18,800 --> 00:00:21,560
of authenticate user videos.

6
00:00:21,560 --> 00:00:24,650
So first of all, let's navigate to job controller.

7
00:00:24,650 --> 00:00:30,200
Like I said, any of these controllers will have access to that user ID.

8
00:00:30,440 --> 00:00:35,240
So in here for get all jobs, I'm not looking for all of the jobs.

9
00:00:35,240 --> 00:00:41,300
In fact, this is something that only admin is going to be able to see later on.

10
00:00:41,950 --> 00:00:44,250
So in this case, I want to change this around.

11
00:00:44,260 --> 00:00:50,620
Remember, this is a filter object and effectively I want to go with created by.

12
00:00:50,650 --> 00:00:56,920
So that's the property and I want to set it equal to rec dot user user ID.

13
00:00:57,130 --> 00:01:06,460
So as a result, when the user makes the request with a cookie with the token, we only provide jobs

14
00:01:06,460 --> 00:01:10,180
that belong to that specific user.

15
00:01:10,780 --> 00:01:16,270
And not only that, but also when we create the job, of course we need to provide that property.

16
00:01:16,300 --> 00:01:23,410
Now there's million ways how we can set up, but a one liner is following where essentially I have req.body

17
00:01:23,500 --> 00:01:31,570
in there I have the user with the user ID correct, So I can just attach one more property the created

18
00:01:31,570 --> 00:01:32,140
by.

19
00:01:32,170 --> 00:01:35,650
Correct, because that's what the job model is looking for.

20
00:01:35,650 --> 00:01:39,820
And then we're going to go with req dot user and then user ID.

21
00:01:40,660 --> 00:01:47,440
So essentially, since we're passing here, the erect body, I'm just attaching this created by to the

22
00:01:47,440 --> 00:01:50,950
object and I'm setting it equal to the user ID.

23
00:01:51,190 --> 00:02:00,130
So as a result, if we are going to go right now to our Thunder client, and let's just start by creating

24
00:02:00,130 --> 00:02:00,780
a job.

25
00:02:00,790 --> 00:02:04,690
So this will be the company position and all that.

26
00:02:04,720 --> 00:02:06,490
Let me send it over here.

27
00:02:06,490 --> 00:02:11,230
And if everything is correct, I'm also going to see the created by.

28
00:02:11,260 --> 00:02:19,150
So, of course, this is going to be the ID for the user, John, Basically for my first user.

29
00:02:19,150 --> 00:02:25,030
And if I'm going to change this around and if I'm going to go with Apple and.

30
00:02:26,210 --> 00:02:27,920
Let's go DevOps over here.

31
00:02:28,750 --> 00:02:30,640
Then of course, we'll create this job.

32
00:02:30,640 --> 00:02:36,190
And now if I go and check get all jobs, I should see two of them.

33
00:02:36,190 --> 00:02:38,460
Now, of course I have over here cookies.

34
00:02:38,470 --> 00:02:41,680
So let me go to response and check it out.

35
00:02:41,950 --> 00:02:46,780
I see these two jobs now if I'm going to register another user.

36
00:02:47,550 --> 00:02:48,450
And you know what?

37
00:02:48,480 --> 00:02:50,490
I'm not going to be particularly original.

38
00:02:50,490 --> 00:02:52,260
I'm just going to go with Peter and Peter.

39
00:02:52,290 --> 00:02:54,890
Let me send remember, first we need to register.

40
00:02:54,910 --> 00:02:55,190
Okay.

41
00:02:55,200 --> 00:02:56,200
User created.

42
00:02:56,220 --> 00:02:58,080
Then we want to log in.

43
00:02:59,000 --> 00:03:00,590
So this stays the same.

44
00:03:00,590 --> 00:03:02,090
The password and all that.

45
00:03:02,390 --> 00:03:08,810
If Peter makes the request to get all jobs, notice nothing.

46
00:03:09,020 --> 00:03:10,010
Empty array.

47
00:03:10,220 --> 00:03:14,480
So, yes, it's a valid request, but Peter hasn't created those jobs.

48
00:03:14,480 --> 00:03:19,790
So of course, in order for Peter to see any jobs, well, he needs to create few.

49
00:03:19,820 --> 00:03:20,420
Correct.

50
00:03:20,420 --> 00:03:25,910
So let's go over here with Facebook and we're going to go with designer.

51
00:03:26,820 --> 00:03:29,850
So for now, I'm just going to create one job and check it out.

52
00:03:29,880 --> 00:03:37,920
Now, of course, I have this one job, and if I go back to all of the jobs notice now, of course.

53
00:03:38,700 --> 00:03:40,340
I can see only this one job.

54
00:03:40,350 --> 00:03:43,110
So again, if John logs in.

55
00:03:44,660 --> 00:03:49,910
This might be a little bit redundant, but I just want to make sure everyone is on the same page.

56
00:03:50,150 --> 00:03:57,980
If John logs in, if I get the cookie where I have John's credentials, then of course, again we go

57
00:03:57,980 --> 00:03:59,900
back and now we see two jobs.

58
00:03:59,900 --> 00:04:07,340
And again, all of this is happening because we're sending back the cookie with JWT and by default browser

59
00:04:07,340 --> 00:04:12,470
is going to be sending back and essentially on the server.

60
00:04:12,470 --> 00:04:16,190
We'll take a look at the cookie, take a look at the token.

61
00:04:16,190 --> 00:04:21,339
If everything is correct, then we'll proceed to a specific route.

62
00:04:21,350 --> 00:04:27,590
And for example, if I want to delete the job, of course I just need to grab the correct one.

63
00:04:28,400 --> 00:04:29,300
Over here.

64
00:04:31,390 --> 00:04:33,220
And pass it.

65
00:04:33,890 --> 00:04:36,860
In the URL, so I sent the up job.

66
00:04:36,860 --> 00:04:37,280
Delete it.

67
00:04:37,280 --> 00:04:45,440
So now John also has only one job and with this in place we can move on to the next step.

