1
00:00:00,520 --> 00:00:03,900
It looks like at this point, we've got a basic express server in place.

2
00:00:04,470 --> 00:00:09,810
So now let's kick it up a notch and add some more routes and controllers, and we're going to start

3
00:00:09,810 --> 00:00:10,950
with auth setup.

4
00:00:11,310 --> 00:00:17,910
So think log in and register functionality just because I want to show you how JSON web tokens remember

5
00:00:17,940 --> 00:00:20,820
JWT with cookies instead.

6
00:00:21,120 --> 00:00:27,060
So previously, we just sent them with the response in the address on this cache will use cookies.

7
00:00:27,540 --> 00:00:32,369
And also, I want to show you how URL based authentication is going to work because in this project

8
00:00:32,820 --> 00:00:33,900
we'll have users.

9
00:00:34,380 --> 00:00:43,230
But user is either going to be an admin and only admin can perform record operations on the product.

10
00:00:43,590 --> 00:00:45,360
So create, delete and all that.

11
00:00:45,870 --> 00:00:52,770
And we'll also have users or users out of the ones that are making the orders and leaving their reviews.

12
00:00:53,640 --> 00:01:02,640
Now we'll start with a pretty basic setup where I want you to create a model's folder and there will

13
00:01:02,640 --> 00:01:04,080
create a user address.

14
00:01:04,650 --> 00:01:06,150
So create a user model.

15
00:01:06,570 --> 00:01:12,690
And there I want you to create a schema with name, email and password, and all of them will be type

16
00:01:12,690 --> 00:01:13,140
string.

17
00:01:13,180 --> 00:01:20,040
Now we'll add a little bit more info, but just add these basic things and we'll be in good shape at

18
00:01:20,040 --> 00:01:20,650
the very end.

19
00:01:20,670 --> 00:01:25,150
I just want you to export the Mongoose model now before we begin.

20
00:01:25,200 --> 00:01:26,220
Let me stress something.

21
00:01:26,670 --> 00:01:31,850
The goal of these tasks is not for you to remember everything.

22
00:01:31,850 --> 00:01:32,490
Hundred percent.

23
00:01:33,590 --> 00:01:40,370
It's OK to look up the code, for example, I forgot the exact syntax how to create schema.

24
00:01:41,350 --> 00:01:43,630
In fact, this is what you'll do all the time.

25
00:01:44,260 --> 00:01:45,550
You will look up stuff.

26
00:01:45,910 --> 00:01:48,310
You'll probably go to your previous projects and all that.

27
00:01:48,730 --> 00:01:55,090
And there's the reason why we're dragging certain code from one project to another one because we want

28
00:01:55,090 --> 00:01:56,530
to speed up our workflow.

29
00:01:56,890 --> 00:02:04,540
The goal of these tasks is for you to remember the main concept, since once you remember the main concept,

30
00:02:04,780 --> 00:02:06,940
you'll have no problem getting the code.

31
00:02:07,450 --> 00:02:11,290
So if you remember, hey, I need it to create schema what was correct syntax for schema?

32
00:02:11,710 --> 00:02:12,820
Then you'll be in good shape.

33
00:02:13,030 --> 00:02:15,010
That's the goal of these tasks.

34
00:02:15,490 --> 00:02:19,840
And once I'm done rambling, let's just go to our folder.

35
00:02:20,290 --> 00:02:26,170
So again, let me close everything because I have tons of things open here and I'm looking for a starter.

36
00:02:26,470 --> 00:02:32,710
I want to create a new folder, and I'm going to call this model's online instead of the model.

37
00:02:33,040 --> 00:02:34,900
I want to create a user model.

38
00:02:35,380 --> 00:02:36,250
So let's go here.

39
00:02:36,580 --> 00:02:40,570
So in your file, I'm just going to call this user jass.

40
00:02:41,080 --> 00:02:47,650
Now we will import a few other things, but for the time being, we'll just want a mongoose and let

41
00:02:47,650 --> 00:02:51,220
me close the sidebar so my English is equal to acquire.

42
00:02:52,180 --> 00:02:53,620
We're looking for Mongo.

43
00:02:53,870 --> 00:02:56,920
And like I said, we want to create a user schema.

44
00:02:56,920 --> 00:02:58,630
So const user.

45
00:02:59,760 --> 00:03:06,450
User and schema is equal to your new gross when that one schema.

46
00:03:06,960 --> 00:03:12,000
And here we'll start with name, like I said, it's going to be type string.

47
00:03:12,480 --> 00:03:15,210
But I also want to set it up as required.

48
00:03:16,170 --> 00:03:23,640
And as far as the custom message, well, I just start with trow here, and let's just say please provide

49
00:03:24,540 --> 00:03:24,900
name.

50
00:03:25,260 --> 00:03:26,190
Let's say that one.

51
00:03:26,770 --> 00:03:30,960
OK, but I also want to add a max length and length.

52
00:03:31,500 --> 00:03:35,340
And I think for the name, I'm going to go with three or four of them in length.

53
00:03:35,850 --> 00:03:40,270
And when it comes to max length, we're going to go with fifty seven.

54
00:03:40,800 --> 00:03:44,010
And now I have the name property in place.

55
00:03:44,430 --> 00:03:47,250
Well, and we want to do the same thing with an email.

56
00:03:47,880 --> 00:03:52,760
But as far as validation in next video, I'll show you a validator package.

57
00:03:53,270 --> 00:03:58,470
And basically, that's alternative to whatever we were setting up before.

58
00:03:58,860 --> 00:04:06,150
Because if you remember when I worked on Jobs API, when we're setting up the model for the user, I

59
00:04:06,150 --> 00:04:09,510
use this match and I use the irregular expression.

60
00:04:10,080 --> 00:04:14,850
So essentially, we have alternative where we can use a package that does that for us.

61
00:04:15,690 --> 00:04:18,390
So it may go back to the user schema.

62
00:04:18,779 --> 00:04:23,030
And I think I can close this one for now, and let's just copy and paste.

63
00:04:23,040 --> 00:04:24,360
I think it's going to be faster.

64
00:04:24,690 --> 00:04:33,360
Well, renamed, but we'll say that the name is email type will be still string required will be true,

65
00:04:33,840 --> 00:04:36,300
and we'll be looking for email here.

66
00:04:37,290 --> 00:04:42,420
OK, awesome run as far as the validate work on that in next video.

67
00:04:42,840 --> 00:04:45,120
So for now, we can just remove these two.

68
00:04:45,450 --> 00:04:50,610
So email is pretty much required and we just say, please provide email when we want to do the same

69
00:04:50,610 --> 00:04:51,750
thing with a password.

70
00:04:52,320 --> 00:04:57,210
So now take this code and we're just right here, password.

71
00:04:57,930 --> 00:05:00,780
And as far as the message is also going to be password.

72
00:05:01,950 --> 00:05:06,900
Online, we're looking for the mid-length in this case, and we're going to go with six.

73
00:05:07,560 --> 00:05:13,800
So let's just go here with mid-length length and let's set it up as six now lastly, I want to set up

74
00:05:13,800 --> 00:05:14,580
those roles.

75
00:05:14,910 --> 00:05:16,740
And for that, I'll use that in them.

76
00:05:16,890 --> 00:05:25,020
Remember that it was that enum property where we just showcase what possible values the property can

77
00:05:25,020 --> 00:05:25,290
have.

78
00:05:25,680 --> 00:05:31,410
So in this case, with the right URL, I just at a type of string.

79
00:05:32,500 --> 00:05:38,560
And then as far as the enemy's going to go, you know, and as far as the possible values, we're going

80
00:05:38,560 --> 00:05:40,350
to go with admin karma.

81
00:05:40,990 --> 00:05:43,690
And the second one will be user and by default.

82
00:05:44,920 --> 00:05:51,760
Every time we create a user, it's going to be a user, so go it default and we'll set it up as user

83
00:05:52,480 --> 00:05:53,650
at the very, very end.

84
00:05:53,890 --> 00:06:00,970
We want to go with module module that exports and that is equal to mongoose that model.

85
00:06:01,570 --> 00:06:05,130
And then I want to create a user selection.

86
00:06:05,860 --> 00:06:12,340
Basically, it's going to be users, but you get the gist and we're going to set it up as user schema.

87
00:06:12,880 --> 00:06:17,440
And once we have all of this in place, we can move on to the next task.

