Hey there.
Everyone had their share.
And in this video we are going to work with setting up some of the more routes that are kind of essential.
Right now we have just the bare minimum basics.
So we have something which says log out.
Obviously, we know what's going to be the purpose home.
Obviously, we are going to know that this is going to wear out.
We need to protect.
Not everybody should be able to see our home directly.
In fact, without log in and when we click on log in, it says nothing.
As of now, we can actually make this application somewhat like, Hey, I click on login and I can just
simply go ahead and show the content screen.
Definitely possible, but we are going to take it one step further since we have so much of knowledge
of now working with the roots and a whole bunch of other thing.
So let's go ahead and create a simple route here.
And in fact, we can go ahead and call this one as roots.
Roots would be better.
Let's go ahead and create a new file into this one.
And we're going to go ahead and call this one as simply as now.
We have worked on these kinds of things in the past as well.
I'll come back onto this in a second.
This is nothing new for us now in this application, since I told you that once we receive the user
email from the Google, we want to register it to the database.
So it is obvious that we should connect to the database.
Now, usually the database things goes into the config and kind of a requirement or such folder.
But I'm going to take a shortcut here.
I'll just connect the database right up here.
So I'm going to go ahead and say, Hey, I need Mongoose here to connect with the database.
So I'm going to go ahead and say Mongoose Requir and let's go ahead and have the mongoose.
Now, I have shown you so far all the best practices to work with that, but now here I'm going to take
a shortcut here.
So let's go ahead and simply say connect to the DB.
And in order to connect with the DB, I'm going to take a shortcut of Mongoose Dot Connect.
And inside the connect I'm going to go ahead directly pass up simply MongoDB colon slash slash and then
127127.0.0.1
and .0..1.
And then I can go ahead and I have to provide the port number as well to 7017 and then simply passport.
Now as of now, I don't have any database, any user with the name of passport.
My database looks like this.
If I refresh, this is how it looks like.
So it will definitely create a new database entry in this one.
So this is the passport.
And further I'll just have a simple callback that is going to go like this and we'll simply say that,
hey, let's go ahead and console.log here.
So we're going to say console.log and here we are going to say DB connected.
Yes, I know this is a really, really big shortcut and it also got connected.
So some of you might be wondering, hey, why didn't we do it earlier?
Yes, we didn't do it earlier.
Simply reason.
This is a very, very optimistic approach that every single time we are going to have a database connection
like this, there is going to be nothing wrong.
So this is not a best practice.
I am fully aware of that.
But this is what we need as of now.
So assuming whatever we have done, our database is actually get got connected.
Now let's move on to the odd JS.
It is something like what we have worked in the other routes.
Remember the products order kind of exactly same.
So let's go ahead and bring in the router.
So we're going to go ahead and say, hey daughter, go ahead and require the express.
And instead of doing it in two different lines, we can actually go ahead and do this just like we can
do in the case of models as well.
So we're going to go ahead and do this.
And once this is being done, all we got to do is export that.
So we're going to say module dot ports and that is going to export our router.
There we go.
So this is all good.
Now let's go ahead and create some of the login routes up here as well.
So first we are going to create a route that is going to serve.
So we're going to say router, dot, get and what we're going to do is slash login on this login.
We are going to just serve an Aegis template.
So request response like that and we're going to go ahead and simply say rez, dot, render and we're
going to render a simple login page here.
Now this login page doesn't exist.
We will create that in a minute, but just wait for a second.
Now let's go ahead and move on to the index or JS.
What we want to do is now bring that root in inject as a middleware, just like we have been doing in
the past as well.
So let's first require that.
So I'll require that at the top just below the mongoose.
That is fine place for that.
Okay.
So let's go ahead and say that I want this auth.
So auth is going to coming up from REQUIR and this time we need to go.
Okay, so we are in the index, we can directly go inside like that.
So this time this is going to be inside the root and we have just one which is auth.
Okay.
Now we need to inject it as a middleware, so let's go ahead and use that which is going to be simply
app dot use.
Now Abbott use how you're going to use that anyway when says slash what we are going to hand it over
to the all the roads that are handling.
So there we go.
So this should be all good.
Now, the only thing that is remaining now is this index or has worked, has served whatever the purpose
it wanted to be.
Now we can freely work on this one, which is of G is now here.
I can see that there is a log in which is supposed to be there.
So there should be a route slash auth slash login which is not available.
So inside the views, I'm going to go ahead and click on New File and I'm going to call this one as
log in each as now this is going to be exact copy of home JS.
So select everything from home and this one up here.
There we go.
Now what additionally we are going to do, since this is just a log in root itself, it shouldn't have
any more detail.
It should have all the methods that are possibly there to log in into any kind of application.
So I'm going to create a copy of log in and we'll move it up here.
And instead of this success, we are going to go ahead and call this one as simply danger.
In fact, we are going to remove the outline as well.
So let's go ahead and remove this one and let's call this one SBT and Danger.
This is just a red color.
Nothing dangerous on that part.
And we're going to go ahead and call this one.
This is a Google login.
Okay.
Now let's go ahead and see if this is working.
So right now, we cannot travel through the buttons.
We will actually fix that in this video only.
But right now, if I go ahead and say auth slash login, if I go ahead and we see this Google button
up here, we can actually use a little bit of spacing up here.
Margin top of four should be good.
Let's go ahead and hit a refresh and there we go.
Now we have a Google button and everything.
Now let's fix the things that how we are going to actually have these links set up on the home page
as well as this page as well.
So let's go ahead and say first in the home page.
So the log out right now, we haven't created that, but we will eventually create that.
So we're going to go ahead and say in the House, we don't need to say entirety of the path.
It is fully aware of the domain name.
So slash logout is going to be my logout path and when I say login it's going to be slash auth.
Remember in the Edge's file, not the log in js file.
This is how we are serving and home is just home just like always.
Okay, so this is all good for our case.
Let's go ahead and in fact copy this entirely because these are exactly same into the login as well.
So there we go.
We can actually go ahead and paste that.
So this is all good.
This is all so far good.
Now the only problem is let's go ahead and first test it out and see where we are so far.
If I go into home and I'm not able to visit home, yeah, now it is refreshed.
So now I'm able to visit home, I'm able to visit, log in and I'm able to visit, log it, log out,
which is not working as of now, but it will eventually.
Now, the goal in front of me is that if I click on log in, it just lists all the methods through which
I can log in.
As of now, this is Google, but there can be more eventually.
If I click on the Google now, I need to serve that consent to screen.
So how we're going to take this down.
Let's go ahead and catch up in the next video.