1 00:00:01,230 --> 00:00:04,200 Let's continue working on our authentication flow in this video. 2 00:00:04,200 --> 00:00:09,530 I want to give you a quick overview of exactly what we're going to have to do inside of our roots. 3 00:00:09,660 --> 00:00:11,890 Sign up dot t s root handler. 4 00:00:11,970 --> 00:00:13,440 We've got a little bit of code inside of here. 5 00:00:13,470 --> 00:00:17,570 But it's mostly all related to doing some of that validation stuff and whatnot. 6 00:00:19,140 --> 00:00:19,370 All right. 7 00:00:19,380 --> 00:00:22,620 So quick diagram just to make sure it's really clear what we have to do. 8 00:00:22,860 --> 00:00:26,640 This is similar to a diagram we looked at previously but I filled in a couple of steps that we have 9 00:00:26,640 --> 00:00:29,010 to take care of inside of that root handler. 10 00:00:29,010 --> 00:00:34,020 So at some point time or react application is going to make a request to our auth service. 11 00:00:34,020 --> 00:00:39,020 The goal this request is going to be to sign up to inside of that request we're going to have some email 12 00:00:39,050 --> 00:00:40,370 and password. 13 00:00:40,430 --> 00:00:44,540 We're then going to take that email and password into a couple of checks with it in order to sign this 14 00:00:44,540 --> 00:00:50,760 user up to our application the person we need to do is check to see if a user has ever signed up with 15 00:00:50,760 --> 00:00:55,380 this email address before because we're going to make sure that all the different users inside of our 16 00:00:55,380 --> 00:00:58,380 app all have unique email addresses. 17 00:00:58,500 --> 00:01:03,480 So if this email address is already in use we need to stop right away and respond with an air and tell 18 00:01:03,480 --> 00:01:04,500 the react application. 19 00:01:04,500 --> 00:01:09,090 Sorry this e-mails and use to check and see if the e mail is already in use. 20 00:01:09,130 --> 00:01:14,710 We need to take a look at all the users we have saved to our Mongo DB database inside of our database. 21 00:01:14,710 --> 00:01:21,130 We're going to have a collection of users remember a collection of users is essentially a big object 22 00:01:21,430 --> 00:01:26,320 that contains a lot of little objects those little objects each of them is going to represent one user 23 00:01:27,990 --> 00:01:30,040 in order to access that collection. 24 00:01:30,090 --> 00:01:33,280 We have to create a mongoose user model. 25 00:01:33,280 --> 00:01:37,560 So we're going to create a user model that's going to govern access to that collection and help us run 26 00:01:37,560 --> 00:01:42,980 queries or create new users or whatever else so when we say that we need to check and see if user at 27 00:01:42,980 --> 00:01:47,750 this email already exists that really means that we're going to run a query on our database and see 28 00:01:47,750 --> 00:01:52,850 if a user with that email is already inside there and we run that query through this Mongoose user model 29 00:01:55,400 --> 00:02:00,920 if there is not already a user with that email then we're going to move on to the next step we never 30 00:02:00,920 --> 00:02:05,400 store passwords in plain text when we receive a password inside the sign of request. 31 00:02:05,420 --> 00:02:08,120 It will be a plain text password. 32 00:02:08,120 --> 00:02:13,200 Rather than storing that plain text password inside of our database we have to hash it ahead of time. 33 00:02:13,460 --> 00:02:16,070 If you are not familiar with password hashing that is OK. 34 00:02:16,130 --> 00:02:21,340 We'll have a quick follow up video that describes the entire hashing and password storage process. 35 00:02:21,350 --> 00:02:26,000 Long story short we're going to do a little bit of processing on that password before we store it inside 36 00:02:27,950 --> 00:02:28,490 after that. 37 00:02:28,490 --> 00:02:32,810 We're going to create a new user and save them to our Mongo DB database. 38 00:02:32,840 --> 00:02:39,180 And again that's going to happen through our Mongoose user model at that point time after we successfully 39 00:02:39,180 --> 00:02:46,460 save the user whoever made the request to us is now considered to be logged in to reflect that we're 40 00:02:46,460 --> 00:02:52,700 going to send back to our ReACT application a cookie or a Jason web token or something that indicates 41 00:02:52,700 --> 00:02:56,050 that this user is now signed in and authenticated. 42 00:02:56,120 --> 00:03:00,620 We'll have a follow up video to also discuss the actual authentication mechanism that we're going to 43 00:03:00,620 --> 00:03:02,370 end up using. 44 00:03:02,390 --> 00:03:08,510 Right now we're going to focus on these first couple steps all these initial steps really rely upon 45 00:03:08,510 --> 00:03:13,680 creating a mongoose user model so we can work with some data inside of our Mongo database. 46 00:03:13,820 --> 00:03:15,820 That's what we're going to really focus on for right now. 47 00:03:15,860 --> 00:03:18,950 We need to create a mongoose user model. 48 00:03:18,950 --> 00:03:22,900 Now I got just unfortunately a little bit of bad news for you. 49 00:03:22,910 --> 00:03:29,360 We are using Mongoose and we are also using typescript it turns out that TypeScript and Mongoose do 50 00:03:29,360 --> 00:03:32,000 not really cooperate all that well. 51 00:03:32,000 --> 00:03:33,420 I'll be totally honest with you. 52 00:03:33,740 --> 00:03:37,910 There is a library out there that gets Mongoose and typescript to work together a little bit more nicely 53 00:03:38,240 --> 00:03:41,690 but I kind of want to limit the number of libraries that we are using for this project. 54 00:03:41,720 --> 00:03:46,070 So we are going to manually get Mongoose and typescript to interact. 55 00:03:46,070 --> 00:03:47,870 It's not really that hard. 56 00:03:48,110 --> 00:03:52,870 Just a little bit of configuration but unfortunately it involves writing out a decent amount of code 57 00:03:52,910 --> 00:03:56,200 that is kind of challenging to understand inside of a single file. 58 00:03:56,240 --> 00:03:57,540 It's going to take a quick pause right here. 59 00:03:57,540 --> 00:04:01,060 We're going to come back the next video and start to write out this Mongoose user model. 60 00:04:01,100 --> 00:04:06,160 I'm going to do my best to make sure that all this code we write is as crystal clear as can be. 61 00:04:06,380 --> 00:04:10,370 The good news here is that with the code they're about to write out we're going to duplicate throughout 62 00:04:10,460 --> 00:04:14,240 all these different services we create about five six seven times. 63 00:04:14,240 --> 00:04:19,570 So even if this first implementation of a model with mongoose is confusing well we're going to get a 64 00:04:19,580 --> 00:04:21,420 lot of practice doing it. 65 00:04:21,420 --> 00:04:21,590 OK. 66 00:04:21,620 --> 00:04:22,490 So quick browser here. 67 00:04:22,490 --> 00:04:25,310 Let's set up that user model with mongoose in the next video.