1
00:00:00,150 --> 00:00:04,170
Beautiful ones are user schema and model is in place.

2
00:00:04,740 --> 00:00:10,500
Now let's set up a structure for our controller, for the author controller.

3
00:00:10,950 --> 00:00:14,130
And essentially what we're looking for are these three routes.

4
00:00:14,160 --> 00:00:20,640
Now we might add, some other was later on, but for now, we just want to have one for logging, one

5
00:00:20,640 --> 00:00:23,640
for a log out as well as a registered user.

6
00:00:23,940 --> 00:00:29,610
So now we just want to Scafell, and the way we'll do that will create a folder for controllers.

7
00:00:29,820 --> 00:00:32,140
Then we'll create a off control file.

8
00:00:32,520 --> 00:00:36,450
And if you remember why, use this auth controller syntax?

9
00:00:36,450 --> 00:00:43,710
Basically, where I have controller after the file name is because as our project gets bigger, it's

10
00:00:43,740 --> 00:00:50,820
just easier to see whether it is a auth controller award is brute force and all that stuff.

11
00:00:51,180 --> 00:00:53,820
I mean, you can shorten it up to your liking.

12
00:00:53,820 --> 00:01:00,330
But in my case, as the project gets bigger, I rather prefer setting up my file names longer than it's

13
00:01:00,330 --> 00:01:05,430
easier to navigate around the project in their Scafell three functions.

14
00:01:05,580 --> 00:01:11,430
So scaffold, register, log and logout as far as the response, you can just simply go with or read

15
00:01:11,430 --> 00:01:17,780
about and then whatever is the functional one, we want to set up a root folder in there.

16
00:01:17,790 --> 00:01:20,220
We want to create auth or else file.

17
00:01:20,400 --> 00:01:26,820
After that, we want to import all the controllers, set up three routes, reregister and log in are

18
00:01:26,820 --> 00:01:28,390
going to be postrouting.

19
00:01:28,470 --> 00:01:30,720
Remember, you have two options how you can set it up.

20
00:01:31,200 --> 00:01:37,050
Either you can go with a router and then the method name or you can go router or that route.

21
00:01:37,230 --> 00:01:41,880
That's really up to you, and the log out is going to be a get one.

22
00:01:42,420 --> 00:01:46,580
So once we have that in place, then we can import all throughout.

23
00:01:46,590 --> 00:01:51,390
And Mike this, I'm going to name it in the app just as off roader.

24
00:01:51,840 --> 00:01:59,250
And then we want to set up the middleware where we're going with abduct years API version one off and

25
00:01:59,250 --> 00:02:01,650
we'll set it equal to the auth router.

26
00:02:02,040 --> 00:02:04,080
So let's start working on that.

27
00:02:04,470 --> 00:02:11,580
And first, I want to navigate to the star, want to create a new folder, and we'll call this controllers

28
00:02:12,210 --> 00:02:13,620
now inside of the file.

29
00:02:13,920 --> 00:02:17,550
We're going to go or I'm sorry, inside of the folder, we're going to go with off.

30
00:02:19,240 --> 00:02:20,140
Controller.

31
00:02:21,300 --> 00:02:27,570
And then, like I said, I'm actually it's not as inside of the off controller lets scaffold those three

32
00:02:27,570 --> 00:02:35,250
functions one register, one log in and one log out seconds and just say, Register, we're going to

33
00:02:35,250 --> 00:02:37,170
be looking for a sink.

34
00:02:37,170 --> 00:02:39,660
In this case, we want to go with Iraq and the rest.

35
00:02:40,290 --> 00:02:46,740
And as far as the response, like I said, we're just going to go with that's and and let's call this

36
00:02:47,340 --> 00:02:48,000
register.

37
00:02:48,150 --> 00:02:50,880
So let's say here in the string register.

38
00:02:51,750 --> 00:02:54,930
Then we have this in place, you can just copy and paste.

39
00:02:55,530 --> 00:02:57,600
It's going to be a log-in functionality.

40
00:02:58,450 --> 00:03:03,880
So log in, I mean, let's add here, user, just so it makes a little bit more sense, so register

41
00:03:03,880 --> 00:03:05,770
user logged in user.

42
00:03:07,130 --> 00:03:12,680
Log in years there and then third, one is going to be log out user, so log out.

43
00:03:13,580 --> 00:03:14,510
And user.

44
00:03:15,660 --> 00:03:22,290
So once they have all the functions below, I'm going to go with module module.

45
00:03:23,350 --> 00:03:28,960
That exports and I'm going to be exporting object because I might add some other functions there as

46
00:03:28,960 --> 00:03:29,290
well.

47
00:03:29,770 --> 00:03:32,020
I might just go here with a register.

48
00:03:33,030 --> 00:03:35,700
Log in and log out.

49
00:03:36,340 --> 00:03:39,360
So those are my three functions for the controller.

50
00:03:39,900 --> 00:03:40,230
Do that.

51
00:03:40,230 --> 00:03:46,620
We want to create a root folder and in there we want to create auth routes file.

52
00:03:47,250 --> 00:03:50,120
So let's set it up in our new folder.

53
00:03:51,210 --> 00:03:54,440
And let's call this out in there.

54
00:03:54,790 --> 00:03:57,240
What's great, author Alex files off.

55
00:03:58,400 --> 00:04:01,230
Off crowds and just.

56
00:04:02,550 --> 00:04:09,750
That inside of the file in the authorized file, you want to set up all of our routes and we want to

57
00:04:09,750 --> 00:04:11,500
import the controllers, correct?

58
00:04:11,520 --> 00:04:13,500
Now first, we want to set up tomorrow.

59
00:04:13,920 --> 00:04:15,420
So let's remember how we did that.

60
00:04:15,420 --> 00:04:19,110
So we're going here with Express that is equal to require.

61
00:04:19,640 --> 00:04:22,019
We're looking for the express package, correct?

62
00:04:22,680 --> 00:04:29,530
And we want to go with const router and that is equal to express dot and router.

63
00:04:29,550 --> 00:04:30,600
So we need to invoke it.

64
00:04:31,080 --> 00:04:37,260
And once we have the router in place now, let's get all of the functions, all the controllers from

65
00:04:37,260 --> 00:04:40,470
the off controller, probably the fastest way.

66
00:04:41,220 --> 00:04:42,450
Simply grab the object.

67
00:04:42,720 --> 00:04:45,290
So don't take module vortex ports and all that.

68
00:04:45,720 --> 00:04:47,250
Just take the object.

69
00:04:47,430 --> 00:04:48,600
Or I'm sorry, I cut it out.

70
00:04:49,290 --> 00:04:50,940
I want it only to copy that.

71
00:04:51,540 --> 00:04:53,110
And then we we want to go with Konst.

72
00:04:53,430 --> 00:04:56,040
We've get the object and that is coming from.

73
00:04:56,430 --> 00:05:00,930
And now let's look for the controllers, controllers and off the controller.

74
00:05:01,320 --> 00:05:08,230
So I have all my three functions, and like I said, we're going to have these routes post four registered

75
00:05:08,250 --> 00:05:11,970
post for logon and then get four logout.

76
00:05:12,570 --> 00:05:18,930
And in my case, I think I'm going to go with router dot and then post and get.

77
00:05:19,620 --> 00:05:21,060
That's just going to be my preference.

78
00:05:21,070 --> 00:05:22,380
So let's just go here with.

79
00:05:23,310 --> 00:05:29,790
Reporter then post and we're looking for a register that's going to be the route.

80
00:05:30,270 --> 00:05:34,320
And as far as the controller, well, we average there, correct?

81
00:05:34,770 --> 00:05:35,760
Let's copy and paste.

82
00:05:36,150 --> 00:05:38,040
We're looking still for a post.

83
00:05:38,670 --> 00:05:40,110
Now the route is going to be different.

84
00:05:40,110 --> 00:05:45,990
This is going to be a logging one and we're going to be looking for to log in functionality, log logging

85
00:05:45,990 --> 00:05:46,410
function.

86
00:05:46,740 --> 00:05:55,050
One last one will be get and we're going to be looking for the logout logout and that's the function

87
00:05:55,050 --> 00:05:55,290
name.

88
00:05:55,680 --> 00:05:55,980
OK.

89
00:05:56,490 --> 00:05:56,970
Awesome.

90
00:05:57,300 --> 00:05:58,140
Everything is working.

91
00:05:58,150 --> 00:05:59,670
Really, really nice now.

92
00:05:59,670 --> 00:06:06,840
Interesting to go with module that exports and we're exporting a router and the final step we want to

93
00:06:06,840 --> 00:06:08,630
go to App J.S..

94
00:06:09,090 --> 00:06:17,190
And in there, you want to get our router, the author, and then we want to set it up equal to our

95
00:06:17,250 --> 00:06:17,670
route.

96
00:06:17,760 --> 00:06:18,150
Correct.

97
00:06:18,570 --> 00:06:24,420
So let's navigate their app, Jess, and let me just decide where I want to place it.

98
00:06:24,630 --> 00:06:26,220
So I have my database.

99
00:06:26,220 --> 00:06:27,630
I have the packages.

100
00:06:28,550 --> 00:06:35,990
And I think I'm going to go above the Middle East, but between database, and that's just my preference,

101
00:06:35,990 --> 00:06:37,070
how I structure everything.

102
00:06:37,490 --> 00:06:39,620
So let me add here a comment routers.

103
00:06:40,670 --> 00:06:46,790
And first will be the off roader, the concert off roader is equal to or acquire.

104
00:06:47,150 --> 00:06:50,520
And we're looking for the Roots folder right here.

105
00:06:50,900 --> 00:06:54,230
So we're looking in the roots and then we want authors out.

106
00:06:54,800 --> 00:07:02,000
And now let's go below the forward slash in here, and let's just set up the middleware that we want

107
00:07:02,000 --> 00:07:05,990
to use, and that is going to be about years and years.

108
00:07:06,290 --> 00:07:08,070
And then remember the road route.

109
00:07:08,330 --> 00:07:17,360
It's going to be API version one and nine woodland for us, and we'll assign it to author rather and

110
00:07:17,360 --> 00:07:22,430
next video test everything and a postman just so we can see that we're getting correct responses.

111
00:07:23,090 --> 00:07:31,880
But if you have the middleware in the app, yes, if you have the off roads file as well as off controller

112
00:07:32,360 --> 00:07:38,210
with the scaffold at functions, then we're in good shape and we can move on to the next step.

