1 00:00:01,420 --> 00:00:04,450 Let's continue development of our authentication service. 2 00:00:04,450 --> 00:00:08,470 Now I've got to be honest with you in the next coming videos a lot of the authentication stuff we're 3 00:00:08,470 --> 00:00:11,340 gonna put together is pretty boilerplate. 4 00:00:11,350 --> 00:00:16,900 In other words we're gonna write out a lot of Express and authentication related stuff that is not necessarily 5 00:00:16,900 --> 00:00:18,820 related to micros services. 6 00:00:18,820 --> 00:00:21,580 So you might be tempted to skip over a couple of these videos. 7 00:00:21,610 --> 00:00:26,290 However I would encourage you to watch them through even if you are familiar with authentication because 8 00:00:26,290 --> 00:00:30,700 we are going to make one or two kind of interesting design decisions that are going to have impacts 9 00:00:30,700 --> 00:00:33,300 on some of the other services we're going to build down the line. 10 00:00:33,310 --> 00:00:36,440 So again I do encourage you to stick around. 11 00:00:36,540 --> 00:00:36,890 All right. 12 00:00:36,900 --> 00:00:38,840 So what are we gonna do in this video. 13 00:00:38,850 --> 00:00:44,580 Well inside of our index not to yes file which is inside the off service directory right now we currently 14 00:00:44,580 --> 00:00:51,000 have some very simple code we're creating our Express application and one root handler the first thing 15 00:00:51,030 --> 00:00:55,800 that we're going to make very consistent around all the different services we end up creating is going 16 00:00:55,800 --> 00:00:57,780 to be our file and folder structure. 17 00:00:58,350 --> 00:01:03,470 So we're going to end up creating all of our different root handlers inside their own separate files. 18 00:01:03,570 --> 00:01:06,560 So each handler gets its own separate file. 19 00:01:06,720 --> 00:01:11,440 So in other words we are not going to create anything like this right here inside of our index not to 20 00:01:11,440 --> 00:01:13,600 yes file at the root of our project. 21 00:01:13,620 --> 00:01:17,960 Instead we're going to create a separate file to set up a root handler like this again. 22 00:01:17,970 --> 00:01:21,310 There's not a particular micros services reason for doing this. 23 00:01:21,390 --> 00:01:25,590 It's just a convention I came up with I decided made a lot of sense in this course to keep our code 24 00:01:25,650 --> 00:01:33,990 really really organized so inside my SRT directory I'm going to make a new folder called Roots and then 25 00:01:33,990 --> 00:01:39,510 inside they're going to create one file for each row handler that I expect to create in total I think 26 00:01:39,510 --> 00:01:46,150 we need four separate root handlers one for sign up sign in sign out in current user so going to create 27 00:01:46,150 --> 00:01:50,210 those four separate files inside of this roots directory. 28 00:01:50,310 --> 00:01:55,210 I'm going to first create a new file called sign n t s. 29 00:01:55,440 --> 00:02:07,130 I'll do another one called sign out dot t s a third of sign up dot t s and then finally print dash user 30 00:02:07,180 --> 00:02:08,140 dot to us. 31 00:02:08,300 --> 00:02:12,270 You'll notice I put a dash in here even though the route is just current user by itself. 32 00:02:12,320 --> 00:02:15,670 So this could be a current user could be current dash user. 33 00:02:15,680 --> 00:02:18,700 I'll leave it up to you but I'm going to go with dashes in all my file names. 34 00:02:20,710 --> 00:02:20,930 OK. 35 00:02:20,960 --> 00:02:25,680 So there's our force up our files each of these files are going to look very very similar and each them 36 00:02:25,700 --> 00:02:29,720 we're going to set up a different route handler the way that we're gonna set up these root handlers 37 00:02:29,780 --> 00:02:33,980 might be a little bit different than what you're used to seeing if you're used to seeing Express and 38 00:02:33,980 --> 00:02:36,030 working with express in this fashion right here. 39 00:02:36,050 --> 00:02:37,280 That's not quite what we're gonna do. 40 00:02:37,280 --> 00:02:40,270 We're going to do something just ever so slightly different. 41 00:02:40,300 --> 00:02:44,830 So let's go and put together an equivalent route handler for current user. 42 00:02:44,930 --> 00:02:45,680 I'm going to go backwards. 43 00:02:45,680 --> 00:02:53,810 The current user dot test file and then at the very top I'm going to import in Express from Express 44 00:02:57,400 --> 00:03:04,320 I will then create something called a router will say express dot router and then finally I'm going 45 00:03:04,320 --> 00:03:09,380 to say router not get the same route we just put together a moment to go. 46 00:03:09,420 --> 00:03:12,660 So API users current user 47 00:03:16,150 --> 00:03:27,230 and then finally at the bottom I'll do an export of router as current user router with the structure 48 00:03:27,230 --> 00:03:31,340 that you see right here is what we're going to be doing inside of all of our different grout files. 49 00:03:31,340 --> 00:03:32,920 We're going to import Express. 50 00:03:33,050 --> 00:03:37,670 We're gonna set setup a router which is an object that we can use to associate roots with and then at 51 00:03:37,670 --> 00:03:39,920 the very bottom we're going to export that router. 52 00:03:39,920 --> 00:03:43,190 And as we do we're going to rename it at the same time. 53 00:03:43,310 --> 00:03:47,590 The reason we are renaming that exports with this router as current user router is that we're going 54 00:03:47,590 --> 00:03:52,010 to end up with many different routers inside of our application so they can't all be called router. 55 00:03:52,070 --> 00:03:53,620 You have to be called something different. 56 00:03:53,670 --> 00:04:00,020 So we're going to do a little renaming step down here at the bottom well then save this file and I want 57 00:04:00,020 --> 00:04:04,370 to show you how we're going to associate this router with our Express application back inside the index 58 00:04:04,370 --> 00:04:10,550 dot t yes file so I can go back over to index dot to yes I'm going to delete that existing root handler 59 00:04:11,270 --> 00:04:15,130 because we've now moved it into a separate file at the top. 60 00:04:15,160 --> 00:04:26,750 I'm going to import weren't user router from roots weren't user and then to associate that router object 61 00:04:26,750 --> 00:04:35,880 with our app we'll write out app not use burnt user router like so so everything that we just wrote 62 00:04:35,970 --> 00:04:42,390 between that current user file right here and this line right here and that line right there we're going 63 00:04:42,390 --> 00:04:47,880 to repeat throughout the rest this course many many times once for every single different root handler 64 00:04:47,940 --> 00:04:55,820 we put together I want to just tell you really quickly there's no particular reason that we're creating 65 00:04:55,820 --> 00:05:00,470 a router over here we're not really going to have any one off middle wares or anything like that we're 66 00:05:00,470 --> 00:05:02,830 not going to really have groups of routes or anything like that. 67 00:05:02,930 --> 00:05:08,150 I just decided that creating a router object to made this code look very easy to understand and nice 68 00:05:08,390 --> 00:05:13,810 we could just as easily just export a plane function and then associate those functions with our app 69 00:05:13,820 --> 00:05:16,730 back inside the index not to yes file at the end of the day. 70 00:05:16,760 --> 00:05:21,620 There are a tremendous number of different ways we can associate roots with an express application. 71 00:05:21,620 --> 00:05:25,280 So I just chose one right here that I thought made sense to me on this project. 72 00:05:25,280 --> 00:05:27,530 If it doesn't look familiar that's Tony okay. 73 00:05:27,530 --> 00:05:31,990 I'm pretty sure that you're going to be able to understand what's going on here really really quickly. 74 00:05:32,030 --> 00:05:36,320 Now that we've got a good idea of how we're going to write out all of our different root handlers across 75 00:05:36,470 --> 00:05:37,820 all these different projects. 76 00:05:37,880 --> 00:05:40,520 Let's continue with our authentication service in the next video.