For everyone.
After we already complete the sign and sign up, we need to create the authentication rules for protected
row.
Okay, so let me show you.
Inside the folder I will create a new file will be our rules DS.
And let's go to the documentation overview and choose rules.
And we need to copy the listing okay.
Not try to remember this.
I will boost over here.
And we have our graph right.
Right here what we need to do.
We will switch into the request.
Right?
This is the acne right here.
We can boost the request.
From sprite.
Okay.
We need to extract the token from here.
For example, we like the.
We have a some root project route.
Possible profile or something like that.
Let me show you what I mean right here.
Request dot headers dot authorization.
Okay.
And right here you can return true right now.
Let me show you how we can do that.
For example.
In my way I will create one more controller inside the user.
I will build us into the user and get profile.
Users.
Let us.
Aggregate base and boost right here.
I guess current users.
And right here I will get user like this.
Profile.
Now I will say we already lost our data, right?
But now let me show you how we can use the graph in order to use the raw lecture documentation again.
We will use the right use graph.
Let me invoice directly inside the class.
And remove the authentication.
Let me say authentication.
Go directly over here.
And let me get again to see what is inside console.log.
So here after we said successfully.
I need to copy something.
And what is our getprofile.
Right.
So the parallel token.
And I will say right here you can check.
It will cost a lot.
The bearer Hogan from judo, right?
Right here.
We need to check and follow.
We will check the token.
Right.
With request dot header.
Dot authorization.
What about if we doesn't put anything?
Let's say.
Right here I will show no authentication.
I will say we got to modify.
Okay.
What about if I show the token.
But I don't send anything.
We will also get undefined.
So right here we need to check.
Right here.
I think we can submit directly.
Like.
We always do.
Okay.
And I will show the second one to extract the token, the JavaScript node.
And we need to check if we doesn't have any token we will throw new on authorize, etc..
Okay.
You can boost some message over here right now.
I will not do this to say what is the default.
Right here.
Let me test.
If I don't slice the token I will say now it will send a message will be unauthorized.
Please see the default message.
Okay.
You can customize it if you want, but right now I think this will be good with this message.
After we already have a token.
What we need to do, we will verify it, right?
So right here we need to verify that if you remember these are the authentication service.
We will inject the generate service and we will size thus right.
In this case we need to do that also.
This is just a class for a reason.
We can inject us with a constructor.
Okay.
We will.
Inject the service over here.
Let's say.
A lot of it and let it run.
Right here.
We got error.
Right.
This side.
We saw result say injection.
Inside user module.
Why?
Why the user module?
Because you can see right here.
In order to use the authentication rule I already invoked us inside this case.
Right.
So for that reason.
We need to import.
Also.
It may not fix the issue.
We will go back to where we use the authentication graph.
It means that the user module we need to import the.
Module.
Now you can say.
It will fix that issue.
We can fix thus dependencies issue by import the module inside the module.
We use the log right.
But But I don't want that at all.
You can say it later.
We will have a maybe 100th module.
I want one go up and boost the module one by one in every module.
I will create later.
Okay.
I want to, but it will be global.
So how we can do that.
Let me remove and we will got the error right.
In order to fix that issue in the best way.
Let's go to the authentication module.
Also right here what we need to do.
You can say right now we already mark the authentication module will be global.
Okay.
And by the end of the day, it will import inside the app module over here.
Right now we need to export.
The module.
But the 40.
And we still have error.
Secondly we will mark this thing will be global.
Now you can see it already fits the issue right.
Let me tell you why.
Firstly the app module it will import the authentication module right.
And authentication module it will export the module itself.
And this will mark a Tiger team will win the global race.
Module.
Okay.
It means entire authentication module right here will become a global module.
And because this is the global module we can use the authentication module everywhere with our imports.
And one more step.
We already exported entire module itself.
It means the module right now is already become a global also okay.
That is.
Right.
This will fix the issue.
You can say and let me go back to the go.
We already got the token right and we already inject charge of it.
Right here.
We need to.
Verify that.
And right here we need to use a C function.
And let me remove the boolean.
Here.
So.
So do not verify C we need to boost the token.
Right.
The token.
And.
This is the a.
Why.
So for that reason we need to wrap it inside a try catch block.
Over here.
So let me say right here, after we already verifies the token we will copy the code.
This user.
Right.
Let me console.log.
What is right here?
Let us.
I will say, and you already got the decoded user over here, right?
After we already got user.
We will attach this.
Right.
Right here.
We will attach this thing into the request.
Request dot current user okay.
We will pass it to your current user.
We will.
The buy long sell.
Right here.
I will give you the ID.
We already got this user dot underscore id.
Name of the user dot name and email user.
ID.
And of course we will fit the task group okay we will fit the task group.
Let me show you how we can fix that.
Firstly with the code the user right here.
I will create an interface for us.
Right.
Um.
Insert a row insert as our save folder.
I will create a new file called global.
Yes.
This will become a global task.
Right here I will provide the input file.
Okay.
Will be right.
Here.
I use my log.
File name and email.
I will move over here.
And inside here I will pass the.
R user by Why not?
Please.
And, uh.
Um.
We have a script right now.
Please see the airline issue.
Um.
Beside this assertion is.
Is unnecessary.
Okay.
I will ignore that also.
Seated.
Buddhas over here.
Okay.
And right here.
We already are lost.
And this theta thing.
I will cut it.
Also a user by lot.
And inside the request, we need to, uh, add pass the current user into the request object.
Let me show that this is the request from the spread.
Right.
Express.js script passed to request object.
I will show some stuff like that and you can read in here.
Now, now what we want is an express request object using TypeScript.
You can just written and we will declare something like that.
Let me copy and go to the global standards right here.
We will use the current user with I user ballot okay.
And right now it already fit the issue right.
We already got the user ballot over here.
Very very good right.
That's the how we can override or actually we already extend the new property inside the library.
And if we have any An error revealed rose or not?
Realization is actually not so.
And let me test that.
Okay.
It's already work.
And right here we need to return.
True.
Okay.
Actually, we already return over here.
If we have any error, it will throw.
Okay.
For example, if I type some invalid token, say okay, it will log the error unauthorized.
Very very good.
Right.
And say right here we already got the user.
So that is not how we can create the.
authentication to golf and the POI.
In this video I hope you understand the global.
Over here it will mark the user authority.
The authentication module will become null globally.
And we also export the module itself okay.
Because entire thing in this module right here will be become a global.
So much work.
We will explore that okay.
Because we want the module is now.
Global also.
Right.
We will mark that will be global.
That's for the video I will see you in the next one.