Hey there, everyone that they share.
And in this video we're going to discuss about manager role.
The majority of my courses and even other courses, people usually talk about the admin role and the
user role.
But this one, this time I want to give you more access so that you can create as many roles as you
wish, manager, sub sales, whatever you like to give the information.
So let's go ahead and work on the fictitious manager route.
So what we're going to do in this route is just like we have admin, all user, we give all the details
to admin, which we should his admin of the application, but maybe there is a manager and we want to
give him some information and it's up to you.
Maybe you want to give him only the name and phone number, not the emails, maybe email and the name,
not the phone number.
So it's up to you how much you want to have a control on that.
Now, in the other case, what we're going to go ahead and work on with is this is a manager who wants
to get all the access of the data, but we will we don't want to share that.
Who are other admins or other managers for him?
So only the user who are having a role of user.
We want to just give the information of that.
So for that we just design the role just like we have designed the admin admin user.
So remember these admins and everything they don't really care about.
These are just functionality.
PR functionality we don't care about.
Is manager using it, is somebody else using it.
We are defining it as admin or user just for our sake.
Usually we don't do that, so let's go ahead and change this one.
In this case, we are going to go ahead and provide a simple manager, all users.
So this is going to be the all user for manager.
Now this time I don't want to find all the users.
I want to find or provide a query itself that only find the people whose role is defined as user.
So this will now give me the detail of all the users who are marked as simple user.
Now, if I go ahead and look into my database itself right now, current database looks like this.
So I have one admin which is two.
I have a three with an extra E at AE which is marked as manager.
So in theory I should be getting just one user in my detail, which is just this guy, which is one
at AE.
Let's go ahead and see that how we can actually work on with that.
So this is all great.
Now let's go ahead and bring this route.
We're going to go ahead and move on to the routes.
We'll first say that, hey, this is a new controller now coming in and this is also going to be there.
So let's go ahead and extract that.
In fact, I would like to put a mark on here.
This is a.
Manager only route and this above one is actually admin only routes.
So let's go ahead and say admin only routes.
Yeah, routes make sense and this we have just one.
So route is OC.
So we need to obviously change the route here as well.
This should be manager now.
So slash manager slash user or you can say admin manager because there can be only one for admin.
If you are going to go ahead and use the same route, then it's going to get confused at which should
I run?
And only the first one which it sees, it's going to run that.
So please don't do that.
And here we are going to say this one is for manager only.
And the one this is the one.
So what is going to happen now?
Now what is going to happen?
The custom role obviously is logged in, will inject all the user information.
We'll extract that in the custom role.
In the custom role we are passing on manager.
So this manager will get injected into this array since we are spreading this array right out of the
box.
So it will inject it into this roles array.
So there is one property in the roles array which is manager.
This will check now that this array, which has just one value managers, includes whatever the role
you are saying from the database.
So if you are really manager as according to the database, then this will give me a true value.
So if the value is true, I'm converting that into a false by putting an exclamation sign.
That means, hey, like you get the idea.
I'm not super confuse it, but I hope you get the idea that this is how it is working up.
So if you are if you are not who you are saying, then you'll get a responses error.
Otherwise it's all okay.
Okay.
So let's go ahead and save this one and let's go back on to this one.
Not this one.
Yeah, this is the one.
So now if I go ahead and visit the manager, then I should be getting all the details.
So let's go up here.
I'll go into the logout and hit the send.
So everything is logged out now first let's log in from the to actually I would love to log in from
two and send that and now we are logged in.
Let's try to get all the details.
I am admin so let's go ahead and send this one and I'm getting all the resources available.
So that is fantastic.
Now let's go ahead and log out, send this one and let's log in.
And again, this three is having an extra E.
There we go, triple E, let's go ahead and send.
So I'm now logged in as a three and now let's go ahead and kind of save as this one.
So this one is actually manager, manager, all users save that and this time the route is actually
manager slash users.
If I go ahead and send this one the notice here, this time it says, hey, success is true, but I'm
receiving only one user which is marked as user itself.
Now let's go ahead and sign up another user so that at least we can see some of the data as well.
So we're going to go ahead and mark this one.
We can actually use the post mine itself.
Let's go ahead and use for instead of having an extra three, let's go ahead and use the four.
We are going to go ahead and say this is a user four, I'll use the same password, but I'll choose
a different image this time.
Let's select this one and the image that I'll be using a little bit difficult.
I'll use this logo here.
Let's go ahead and upload that and send this one.
And hopefully this will be uploaded and everything.
So this time all the users are being logged in.
But interestingly, since this should actually change the cookies itself, so it's a great time to check
whether the manager is having all of that.
So let's send this one.
And now we are sending error because our cookie is being replaced by somebody who is a user, not the
admin or the manager.
So let's go ahead and say that you should log out and notice here how Postman is actually helping us
ridiculously well.
And that's why people love Postman.
So we're going to say four.
Let's log in there.
And we shouldn't be logged in with four.
We should be logged in with three to check that.
My bad.
So three with an extra E send that cookies updated hopefully.
Let's go ahead and C manager all user send that and then we go.
We add this time receiving two data.
So this is the first one and this is the second one, not the second one.
So this is the user.
So we are having a photo as an object itself.
And this object seems like, yeah, this is good, but the rapping is not happening.
Great.
Yeah.
Okay, so this.
In this case, this is the two user.
My bad.
I got unnecessarily confused.
So we have got two users.
The first one is this.
Second one is this.
Okay?
So now you can see and understand that how you can define custom roles.
So go ahead and define in your application, your manager, admin, sales, whatever you like to have.
Let's go ahead and catch up in the next video.