Let's continue development of our authentication service.
Now I've got to be honest with you in the next coming videos a lot of the authentication stuff we're
gonna put together is pretty boilerplate.
In other words we're gonna write out a lot of Express and authentication related stuff that is not necessarily
related to micros services.
So you might be tempted to skip over a couple of these videos.
However I would encourage you to watch them through even if you are familiar with authentication because
we are going to make one or two kind of interesting design decisions that are going to have impacts
on some of the other services we're going to build down the line.
So again I do encourage you to stick around.
All right.
So what are we gonna do in this video.
Well inside of our index not to yes file which is inside the off service directory right now we currently
have some very simple code we're creating our Express application and one root handler the first thing
that we're going to make very consistent around all the different services we end up creating is going
to be our file and folder structure.
So we're going to end up creating all of our different root handlers inside their own separate files.
So each handler gets its own separate file.
So in other words we are not going to create anything like this right here inside of our index not to
yes file at the root of our project.
Instead we're going to create a separate file to set up a root handler like this again.
There's not a particular micros services reason for doing this.
It's just a convention I came up with I decided made a lot of sense in this course to keep our code
really really organized so inside my SRT directory I'm going to make a new folder called Roots and then
inside they're going to create one file for each row handler that I expect to create in total I think
we need four separate root handlers one for sign up sign in sign out in current user so going to create
those four separate files inside of this roots directory.
I'm going to first create a new file called sign n t s.
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
dot to us.
You'll notice I put a dash in here even though the route is just current user by itself.
So this could be a current user could be current dash user.
I'll leave it up to you but I'm going to go with dashes in all my file names.
OK.
So there's our force up our files each of these files are going to look very very similar and each them
we're going to set up a different route handler the way that we're gonna set up these root handlers
might be a little bit different than what you're used to seeing if you're used to seeing Express and
working with express in this fashion right here.
That's not quite what we're gonna do.
We're going to do something just ever so slightly different.
So let's go and put together an equivalent route handler for current user.
I'm going to go backwards.
The current user dot test file and then at the very top I'm going to import in Express from Express
I will then create something called a router will say express dot router and then finally I'm going
to say router not get the same route we just put together a moment to go.
So API users current user
and then finally at the bottom I'll do an export of router as current user router with the structure
that you see right here is what we're going to be doing inside of all of our different grout files.
We're going to import Express.
We're gonna set setup a router which is an object that we can use to associate roots with and then at
the very bottom we're going to export that router.
And as we do we're going to rename it at the same time.
The reason we are renaming that exports with this router as current user router is that we're going
to end up with many different routers inside of our application so they can't all be called router.
You have to be called something different.
So we're going to do a little renaming step down here at the bottom well then save this file and I want
to show you how we're going to associate this router with our Express application back inside the index
dot t yes file so I can go back over to index dot to yes I'm going to delete that existing root handler
because we've now moved it into a separate file at the top.
I'm going to import weren't user router from roots weren't user and then to associate that router object
with our app we'll write out app not use burnt user router like so so everything that we just wrote
between that current user file right here and this line right here and that line right there we're going
to repeat throughout the rest this course many many times once for every single different root handler
we put together I want to just tell you really quickly there's no particular reason that we're creating
a router over here we're not really going to have any one off middle wares or anything like that we're
not going to really have groups of routes or anything like that.
I just decided that creating a router object to made this code look very easy to understand and nice
we could just as easily just export a plane function and then associate those functions with our app
back inside the index not to yes file at the end of the day.
There are a tremendous number of different ways we can associate roots with an express application.
So I just chose one right here that I thought made sense to me on this project.
If it doesn't look familiar that's Tony okay.
I'm pretty sure that you're going to be able to understand what's going on here really really quickly.
Now that we've got a good idea of how we're going to write out all of our different root handlers across
all these different projects.
Let's continue with our authentication service in the next video.