WEBVTT

00:03.850 --> 00:04.330
Hey there.

00:04.330 --> 00:05.560
Everyone had their share.

00:05.560 --> 00:10.510
And in this video we are going to work with setting up some of the more routes that are kind of essential.

00:10.720 --> 00:12.970
Right now we have just the bare minimum basics.

00:12.970 --> 00:14.870
So we have something which says log out.

00:14.890 --> 00:17.160
Obviously, we know what's going to be the purpose home.

00:17.170 --> 00:19.450
Obviously, we are going to know that this is going to wear out.

00:19.480 --> 00:20.350
We need to protect.

00:20.350 --> 00:22.660
Not everybody should be able to see our home directly.

00:22.660 --> 00:26.410
In fact, without log in and when we click on log in, it says nothing.

00:26.410 --> 00:32.170
As of now, we can actually make this application somewhat like, Hey, I click on login and I can just

00:32.170 --> 00:34.130
simply go ahead and show the content screen.

00:34.150 --> 00:38.770
Definitely possible, but we are going to take it one step further since we have so much of knowledge

00:38.770 --> 00:41.440
of now working with the roots and a whole bunch of other thing.

00:41.440 --> 00:44.080
So let's go ahead and create a simple route here.

00:44.080 --> 00:47.110
And in fact, we can go ahead and call this one as roots.

00:47.440 --> 00:48.460
Roots would be better.

00:48.910 --> 00:51.490
Let's go ahead and create a new file into this one.

00:51.490 --> 00:56.020
And we're going to go ahead and call this one as simply as now.

00:56.020 --> 00:58.780
We have worked on these kinds of things in the past as well.

00:58.780 --> 01:01.240
I'll come back onto this in a second.

01:01.360 --> 01:07.210
This is nothing new for us now in this application, since I told you that once we receive the user

01:07.210 --> 01:10.270
email from the Google, we want to register it to the database.

01:10.270 --> 01:12.910
So it is obvious that we should connect to the database.

01:12.940 --> 01:18.100
Now, usually the database things goes into the config and kind of a requirement or such folder.

01:18.100 --> 01:19.750
But I'm going to take a shortcut here.

01:19.750 --> 01:21.790
I'll just connect the database right up here.

01:21.910 --> 01:25.360
So I'm going to go ahead and say, Hey, I need Mongoose here to connect with the database.

01:25.360 --> 01:30.790
So I'm going to go ahead and say Mongoose Requir and let's go ahead and have the mongoose.

01:30.820 --> 01:36.100
Now, I have shown you so far all the best practices to work with that, but now here I'm going to take

01:36.100 --> 01:37.000
a shortcut here.

01:37.000 --> 01:40.570
So let's go ahead and simply say connect to the DB.

01:40.750 --> 01:45.190
And in order to connect with the DB, I'm going to take a shortcut of Mongoose Dot Connect.

01:45.370 --> 01:53.500
And inside the connect I'm going to go ahead directly pass up simply MongoDB colon slash slash and then

01:53.500 --> 01:58.840
127127.0.0.1

01:58.840 --> 02:01.960
and .0..1.

02:01.960 --> 02:10.600
And then I can go ahead and I have to provide the port number as well to 7017 and then simply passport.

02:10.990 --> 02:15.670
Now as of now, I don't have any database, any user with the name of passport.

02:15.670 --> 02:17.050
My database looks like this.

02:17.050 --> 02:18.850
If I refresh, this is how it looks like.

02:18.850 --> 02:23.230
So it will definitely create a new database entry in this one.

02:23.230 --> 02:24.520
So this is the passport.

02:24.610 --> 02:30.580
And further I'll just have a simple callback that is going to go like this and we'll simply say that,

02:30.580 --> 02:32.770
hey, let's go ahead and console.log here.

02:32.770 --> 02:39.460
So we're going to say console.log and here we are going to say DB connected.

02:40.240 --> 02:44.110
Yes, I know this is a really, really big shortcut and it also got connected.

02:44.110 --> 02:47.020
So some of you might be wondering, hey, why didn't we do it earlier?

02:47.020 --> 02:49.030
Yes, we didn't do it earlier.

02:49.030 --> 02:49.900
Simply reason.

02:49.900 --> 02:54.370
This is a very, very optimistic approach that every single time we are going to have a database connection

02:54.370 --> 02:56.320
like this, there is going to be nothing wrong.

02:56.320 --> 02:58.840
So this is not a best practice.

02:58.840 --> 03:00.040
I am fully aware of that.

03:00.040 --> 03:01.840
But this is what we need as of now.

03:02.530 --> 03:06.640
So assuming whatever we have done, our database is actually get got connected.

03:06.760 --> 03:08.440
Now let's move on to the odd JS.

03:08.470 --> 03:10.810
It is something like what we have worked in the other routes.

03:10.810 --> 03:14.140
Remember the products order kind of exactly same.

03:14.140 --> 03:15.970
So let's go ahead and bring in the router.

03:15.970 --> 03:21.400
So we're going to go ahead and say, hey daughter, go ahead and require the express.

03:22.000 --> 03:26.860
And instead of doing it in two different lines, we can actually go ahead and do this just like we can

03:26.860 --> 03:29.410
do in the case of models as well.

03:29.410 --> 03:30.940
So we're going to go ahead and do this.

03:31.480 --> 03:34.600
And once this is being done, all we got to do is export that.

03:34.600 --> 03:42.340
So we're going to say module dot ports and that is going to export our router.

03:42.370 --> 03:43.120
There we go.

03:43.840 --> 03:45.100
So this is all good.

03:45.100 --> 03:48.280
Now let's go ahead and create some of the login routes up here as well.

03:48.940 --> 03:51.400
So first we are going to create a route that is going to serve.

03:51.400 --> 03:58.000
So we're going to say router, dot, get and what we're going to do is slash login on this login.

03:58.000 --> 04:00.580
We are going to just serve an Aegis template.

04:00.580 --> 04:09.970
So request response like that and we're going to go ahead and simply say rez, dot, render and we're

04:09.970 --> 04:12.910
going to render a simple login page here.

04:12.910 --> 04:14.740
Now this login page doesn't exist.

04:14.740 --> 04:17.560
We will create that in a minute, but just wait for a second.

04:17.860 --> 04:20.640
Now let's go ahead and move on to the index or JS.

04:20.680 --> 04:25.360
What we want to do is now bring that root in inject as a middleware, just like we have been doing in

04:25.360 --> 04:26.320
the past as well.

04:26.620 --> 04:29.170
So let's first require that.

04:29.170 --> 04:32.740
So I'll require that at the top just below the mongoose.

04:32.740 --> 04:34.390
That is fine place for that.

04:34.540 --> 04:34.740
Okay.

04:34.870 --> 04:37.030
So let's go ahead and say that I want this auth.

04:37.030 --> 04:44.260
So auth is going to coming up from REQUIR and this time we need to go.

04:44.290 --> 04:48.400
Okay, so we are in the index, we can directly go inside like that.

04:48.400 --> 04:53.950
So this time this is going to be inside the root and we have just one which is auth.

04:54.340 --> 04:54.640
Okay.

04:54.640 --> 04:58.930
Now we need to inject it as a middleware, so let's go ahead and use that which is going to be simply

04:58.930 --> 05:00.700
app dot use.

05:01.750 --> 05:07.600
Now Abbott use how you're going to use that anyway when says slash what we are going to hand it over

05:07.600 --> 05:09.640
to the all the roads that are handling.

05:09.640 --> 05:10.570
So there we go.

05:10.690 --> 05:12.030
So this should be all good.

05:12.040 --> 05:17.920
Now, the only thing that is remaining now is this index or has worked, has served whatever the purpose

05:17.920 --> 05:18.670
it wanted to be.

05:18.670 --> 05:24.160
Now we can freely work on this one, which is of G is now here.

05:24.160 --> 05:27.190
I can see that there is a log in which is supposed to be there.

05:27.190 --> 05:31.180
So there should be a route slash auth slash login which is not available.

05:31.420 --> 05:35.530
So inside the views, I'm going to go ahead and click on New File and I'm going to call this one as

05:35.530 --> 05:40.180
log in each as now this is going to be exact copy of home JS.

05:40.270 --> 05:43.780
So select everything from home and this one up here.

05:43.780 --> 05:44.470
There we go.

05:44.980 --> 05:49.540
Now what additionally we are going to do, since this is just a log in root itself, it shouldn't have

05:49.540 --> 05:50.440
any more detail.

05:50.440 --> 05:55.450
It should have all the methods that are possibly there to log in into any kind of application.

05:55.450 --> 05:58.870
So I'm going to create a copy of log in and we'll move it up here.

05:59.140 --> 06:04.390
And instead of this success, we are going to go ahead and call this one as simply danger.

06:04.390 --> 06:06.490
In fact, we are going to remove the outline as well.

06:06.490 --> 06:10.500
So let's go ahead and remove this one and let's call this one SBT and Danger.

06:10.510 --> 06:11.520
This is just a red color.

06:11.530 --> 06:13.150
Nothing dangerous on that part.

06:13.150 --> 06:14.860
And we're going to go ahead and call this one.

06:14.860 --> 06:16.150
This is a Google login.

06:16.870 --> 06:17.070
Okay.

06:17.200 --> 06:19.840
Now let's go ahead and see if this is working.

06:19.840 --> 06:22.030
So right now, we cannot travel through the buttons.

06:22.030 --> 06:24.190
We will actually fix that in this video only.

06:24.190 --> 06:30.460
But right now, if I go ahead and say auth slash login, if I go ahead and we see this Google button

06:30.460 --> 06:33.520
up here, we can actually use a little bit of spacing up here.

06:33.940 --> 06:36.700
Margin top of four should be good.

06:37.270 --> 06:39.820
Let's go ahead and hit a refresh and there we go.

06:39.820 --> 06:41.700
Now we have a Google button and everything.

06:41.710 --> 06:46.750
Now let's fix the things that how we are going to actually have these links set up on the home page

06:46.750 --> 06:48.190
as well as this page as well.

06:48.700 --> 06:52.120
So let's go ahead and say first in the home page.

06:53.230 --> 06:58.450
So the log out right now, we haven't created that, but we will eventually create that.

06:58.450 --> 07:01.990
So we're going to go ahead and say in the House, we don't need to say entirety of the path.

07:01.990 --> 07:04.090
It is fully aware of the domain name.

07:04.300 --> 07:12.130
So slash logout is going to be my logout path and when I say login it's going to be slash auth.

07:12.130 --> 07:16.660
Remember in the Edge's file, not the log in js file.

07:16.690 --> 07:21.090
This is how we are serving and home is just home just like always.

07:21.470 --> 07:24.280
Okay, so this is all good for our case.

07:24.280 --> 07:30.220
Let's go ahead and in fact copy this entirely because these are exactly same into the login as well.

07:30.220 --> 07:30.940
So there we go.

07:30.940 --> 07:33.040
We can actually go ahead and paste that.

07:34.030 --> 07:35.050
So this is all good.

07:35.050 --> 07:36.550
This is all so far good.

07:36.610 --> 07:41.530
Now the only problem is let's go ahead and first test it out and see where we are so far.

07:41.530 --> 07:46.990
If I go into home and I'm not able to visit home, yeah, now it is refreshed.

07:46.990 --> 07:52.390
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,

07:52.390 --> 07:55.060
which is not working as of now, but it will eventually.

07:55.420 --> 08:01.030
Now, the goal in front of me is that if I click on log in, it just lists all the methods through which

08:01.030 --> 08:01.720
I can log in.

08:01.720 --> 08:04.360
As of now, this is Google, but there can be more eventually.

08:04.600 --> 08:09.010
If I click on the Google now, I need to serve that consent to screen.

08:09.010 --> 08:10.660
So how we're going to take this down.

08:10.660 --> 08:12.640
Let's go ahead and catch up in the next video.
