1
00:00:00,390 --> 00:00:07,050
Nice, and once we're done with update password functionality, we actually have only one user controller

2
00:00:07,050 --> 00:00:09,300
left the update user one.

3
00:00:09,750 --> 00:00:17,040
But before we work on it, let's set up a create token user function in utils scenes in the upcoming

4
00:00:17,040 --> 00:00:17,550
videos.

5
00:00:17,970 --> 00:00:20,790
We'll have to use the functionality one more time.

6
00:00:21,300 --> 00:00:27,840
And I think at this point, it's better to set up a nifty UTOS function instead of copying pasting the

7
00:00:27,840 --> 00:00:28,560
same code.

8
00:00:29,190 --> 00:00:36,030
Now what am I talking about if we go to auth controller and keeps growing and keeps growing?

9
00:00:36,450 --> 00:00:43,170
Notice when we create the user, essentially I just grab the user and I take these properties and that's

10
00:00:43,170 --> 00:00:46,770
the object, but I'm returning and effectively what I want to do.

11
00:00:46,770 --> 00:00:50,760
I want to set up a function because we will use this function are one more time.

12
00:00:50,780 --> 00:00:54,750
And I mean, once it's already a third time, we're copying pasting.

13
00:00:54,780 --> 00:00:58,110
I think that's a great time to create the utos function.

14
00:00:58,620 --> 00:01:06,270
So steps you need to take, go to read me and first I want you to create a file in the utils.

15
00:01:06,450 --> 00:01:14,880
In my case, I'm going to call this create token user set up the function that accepts a user object

16
00:01:15,450 --> 00:01:17,820
and returns a user token object.

17
00:01:18,300 --> 00:01:22,110
So it gets the object and returns the object.

18
00:01:22,470 --> 00:01:28,920
We have the values and properties that we have already in the controller export as default.

19
00:01:29,130 --> 00:01:37,020
At least that's what I'm going to do when set up correct imports and exports in the utils, as well

20
00:01:37,020 --> 00:01:44,010
as off controller because we'll have to refactor the code and then watch how I struggle doing that.

21
00:01:44,130 --> 00:01:48,870
So once you're done, just the resume the video and see how I'm doing that.

22
00:01:49,140 --> 00:01:51,480
So first, I want to go to your tools.

23
00:01:52,230 --> 00:01:54,900
Want to go with create token?

24
00:01:55,880 --> 00:01:58,620
And user James Run.

25
00:01:58,940 --> 00:02:07,340
We want to set up a function, create token user is equal and essentially I'm looking for a user object.

26
00:02:08,000 --> 00:02:10,840
And what I want to do is just take this code.

27
00:02:10,850 --> 00:02:13,610
So for the last time, we're copy and paste the code.

28
00:02:13,850 --> 00:02:19,280
So cut it out and I simply want to return from this function of this object.

29
00:02:19,790 --> 00:02:26,780
So this is going to be looking for user name or user I.D. as well as user role.

30
00:02:27,240 --> 00:02:28,010
All right.

31
00:02:28,490 --> 00:02:31,040
One, we want to export this as default.

32
00:02:31,040 --> 00:02:31,760
So module.

33
00:02:32,680 --> 00:02:37,390
Exports and we look for create token after that.

34
00:02:38,400 --> 00:02:40,350
We want to go to the next jazz.

35
00:02:41,340 --> 00:02:43,200
And we want to look for the file.

36
00:02:43,830 --> 00:02:49,170
So let's say you're concerned, create token user is equal to require.

37
00:02:50,290 --> 00:02:56,350
And we're looking for a file create token user when we export that, so create token user.

38
00:02:56,770 --> 00:02:58,360
Why don't we go to auth controller?

39
00:02:58,360 --> 00:03:00,640
We check whether we're getting something from the utils.

40
00:03:00,650 --> 00:03:01,360
Yes, we do.

41
00:03:01,780 --> 00:03:05,800
So we have here attach cookies and this is what I'm talking about, where it is.

42
00:03:05,800 --> 00:03:12,190
My preference set up this in next year, because that way I can just explicitly say what I'm looking

43
00:03:12,190 --> 00:03:13,210
for on the utos.

44
00:03:13,210 --> 00:03:21,370
Otherwise, if you just create a bunch of files, then after you set up multiple lines of import, is

45
00:03:21,370 --> 00:03:22,060
that a big deal?

46
00:03:22,270 --> 00:03:23,980
No, but that's just my preference.

47
00:03:23,990 --> 00:03:27,370
So let's go with comma and create token user.

48
00:03:27,790 --> 00:03:31,090
Then I'll say I have some kind of bug somewhere.

49
00:03:31,750 --> 00:03:33,970
Probably, yep, because I removed the code.

50
00:03:34,450 --> 00:03:39,100
So now let's scroll down and the first place where we use the token.

51
00:03:39,910 --> 00:03:44,440
Let's go here and let's say, create token user and let's bask in the user.

52
00:03:44,770 --> 00:03:48,380
So now we're getting back the token user and the same will do over here.

53
00:03:49,050 --> 00:03:52,390
Token user and then we'll just pass in the user.

54
00:03:52,900 --> 00:03:59,320
Now we'll use this code in next VIDEO So if there are some bugs, we'll see that I'm not going to waste

55
00:03:59,320 --> 00:04:02,710
your time right now on checking whether everything is correct.

56
00:04:03,340 --> 00:04:08,080
And once you're done with this, now I can proceed to the next task.

