1
00:00:00,320 --> 00:00:05,360
Well come back in the next few lessons we're going to had user authentication into camp.

2
00:00:05,580 --> 00:00:10,290
So we're going to take everything we learned in the last few lessons where we did the auth demo with

3
00:00:10,290 --> 00:00:13,470
the secret page and we're going to take that and apply it to camp.

4
00:00:13,680 --> 00:00:15,400
And it will be broken into a few steps.

5
00:00:15,420 --> 00:00:20,730
The first one is to add the user model and then also to install all of those packages that we needed

6
00:00:20,730 --> 00:00:21,240
.

7
00:00:21,240 --> 00:00:22,120
Let's get started.

8
00:00:22,300 --> 00:00:26,910
I mean instead of V-6 now I made a new version because we are going to make some substantial changes

9
00:00:26,910 --> 00:00:27,450
here.

10
00:00:27,870 --> 00:00:33,270
And the first thing I'll do is just run an NPM install and install all those packages we need.

11
00:00:33,270 --> 00:00:41,250
So we need passport passport dasht local and passport Dasch local Dasch mongoose and then we also need

12
00:00:41,640 --> 00:00:50,280
express Dasch session and then we'll do dash dash save and we already have Express we already have body

13
00:00:50,280 --> 00:00:52,520
parts or so we should be good to go.

14
00:00:52,860 --> 00:00:55,180
Let's just double check on our package that.

15
00:00:55,560 --> 00:01:02,000
Make sure it has all those packages good Rigaud everything looks good.

16
00:01:02,170 --> 00:01:09,180
OK let's open up abdicates And let's begin by importing some of those different packages.

17
00:01:09,360 --> 00:01:10,110
So we'll import.

18
00:01:10,110 --> 00:01:18,970
Passport is equal to require passport and then we have a local strategy.

19
00:01:19,110 --> 00:01:26,880
Require passport Dasch local and are safe there.

20
00:01:26,880 --> 00:01:32,160
Now let's go about creating our user model which will require here so we can actually start with that

21
00:01:32,220 --> 00:01:34,060
user.

22
00:01:34,150 --> 00:01:41,070
The schools require that slash models slash user which of course will crash right now if we try and

23
00:01:41,070 --> 00:01:41,760
run this.

24
00:01:41,910 --> 00:01:48,330
So let's make the user model so that needs to go inside that model's directory right here we want to

25
00:01:48,330 --> 00:01:49,350
make a file.

26
00:01:49,560 --> 00:01:52,150
Models slash user.

27
00:01:52,320 --> 00:01:53,500
Yes.

28
00:01:53,880 --> 00:01:57,020
And let's open that file.

29
00:01:58,050 --> 00:02:01,940
And then inside of there we're going to add in our basic mongoose code.

30
00:02:02,130 --> 00:02:05,990
So the first thing you want to do is require mongoose.

31
00:02:08,060 --> 00:02:08,660
OK.

32
00:02:08,880 --> 00:02:15,930
And then we need our user schema and remember that our user needs to have a username and password and

33
00:02:15,930 --> 00:02:16,950
both are strings

34
00:02:19,680 --> 00:02:20,980
already.

35
00:02:21,000 --> 00:02:28,340
So instead of here username is a string comma password is also a string.

36
00:02:28,860 --> 00:02:31,770
And then at the very bottom we'll do our module.

37
00:02:31,800 --> 00:02:41,270
Exports equals mongoose top model user Cingular and then the schema to construct it from.

38
00:02:41,550 --> 00:02:44,820
And that's everything we need to do to make a simple user model.

39
00:02:44,820 --> 00:02:49,900
It has no off yet it doesn't have passport plugged in or the passport local mongoose plug in yet.

40
00:02:50,070 --> 00:02:55,650
But let's try to just make sure that this requires working and if we do that now.

41
00:02:55,860 --> 00:02:58,080
Node Yes.

42
00:02:58,470 --> 00:02:59,720
Everything looks good.

43
00:02:59,730 --> 00:03:00,780
Stop the server.

44
00:03:00,930 --> 00:03:03,980
Now let's go and add in the passport local plug in.

45
00:03:04,470 --> 00:03:13,740
So we need to require that here our passport local mongoose equals require passport dash local dash

46
00:03:13,800 --> 00:03:16,390
Mangus which is that package we installed.

47
00:03:16,920 --> 00:03:26,280
And then we just need to do user schema plug in passport local mongoose and save and that's it.

48
00:03:26,550 --> 00:03:28,580
And again that makes it really easy for us.

49
00:03:28,620 --> 00:03:33,750
This basically takes the wheel and it starts to add in some methods to our user.

50
00:03:33,750 --> 00:03:34,950
Now let's test this out.

51
00:03:35,020 --> 00:03:37,750
It's just run the same code node app.

52
00:03:37,830 --> 00:03:38,570
Yes.

53
00:03:38,820 --> 00:03:40,350
Everything works just fine.

54
00:03:40,590 --> 00:03:42,610
Once again good to see.

55
00:03:42,870 --> 00:03:43,230
Great.

56
00:03:43,230 --> 00:03:48,360
So we now have installed all the packages and we've set up the user model and added in the passport

57
00:03:48,360 --> 00:03:53,670
local mongoose plugin which gives all these methods and important functionality to our user model.

58
00:03:53,670 --> 00:03:58,080
And that's all I wanted to do in this video in the next video will actually start working and the functionality
