WEBVTT

00:03.700 --> 00:05.140
Hey there, everyone that they share.

00:05.140 --> 00:07.930
And in this video we're going to discuss about manager role.

00:08.030 --> 00:12.940
The majority of my courses and even other courses, people usually talk about the admin role and the

00:12.940 --> 00:13.510
user role.

00:13.510 --> 00:17.680
But this one, this time I want to give you more access so that you can create as many roles as you

00:17.680 --> 00:21.970
wish, manager, sub sales, whatever you like to give the information.

00:21.970 --> 00:24.940
So let's go ahead and work on the fictitious manager route.

00:25.180 --> 00:29.770
So what we're going to do in this route is just like we have admin, all user, we give all the details

00:29.770 --> 00:34.420
to admin, which we should his admin of the application, but maybe there is a manager and we want to

00:34.420 --> 00:37.090
give him some information and it's up to you.

00:37.090 --> 00:41.650
Maybe you want to give him only the name and phone number, not the emails, maybe email and the name,

00:41.650 --> 00:42.550
not the phone number.

00:42.550 --> 00:45.360
So it's up to you how much you want to have a control on that.

00:45.370 --> 00:50.200
Now, in the other case, what we're going to go ahead and work on with is this is a manager who wants

00:50.200 --> 00:53.440
to get all the access of the data, but we will we don't want to share that.

00:53.440 --> 00:56.020
Who are other admins or other managers for him?

00:56.020 --> 00:58.690
So only the user who are having a role of user.

00:58.690 --> 01:00.640
We want to just give the information of that.

01:00.760 --> 01:05.650
So for that we just design the role just like we have designed the admin admin user.

01:05.650 --> 01:10.000
So remember these admins and everything they don't really care about.

01:10.000 --> 01:11.200
These are just functionality.

01:11.200 --> 01:12.820
PR functionality we don't care about.

01:12.820 --> 01:15.520
Is manager using it, is somebody else using it.

01:15.550 --> 01:18.640
We are defining it as admin or user just for our sake.

01:18.640 --> 01:21.640
Usually we don't do that, so let's go ahead and change this one.

01:21.640 --> 01:26.800
In this case, we are going to go ahead and provide a simple manager, all users.

01:26.800 --> 01:29.200
So this is going to be the all user for manager.

01:29.320 --> 01:31.720
Now this time I don't want to find all the users.

01:31.720 --> 01:38.800
I want to find or provide a query itself that only find the people whose role is defined as user.

01:38.800 --> 01:44.380
So this will now give me the detail of all the users who are marked as simple user.

01:44.400 --> 01:48.520
Now, if I go ahead and look into my database itself right now, current database looks like this.

01:48.520 --> 01:50.440
So I have one admin which is two.

01:50.470 --> 01:56.170
I have a three with an extra E at AE which is marked as manager.

01:56.170 --> 02:00.790
So in theory I should be getting just one user in my detail, which is just this guy, which is one

02:00.790 --> 02:01.360
at AE.

02:02.020 --> 02:05.110
Let's go ahead and see that how we can actually work on with that.

02:05.110 --> 02:06.370
So this is all great.

02:06.370 --> 02:08.410
Now let's go ahead and bring this route.

02:08.410 --> 02:10.990
We're going to go ahead and move on to the routes.

02:11.170 --> 02:17.500
We'll first say that, hey, this is a new controller now coming in and this is also going to be there.

02:17.500 --> 02:18.790
So let's go ahead and extract that.

02:18.790 --> 02:20.740
In fact, I would like to put a mark on here.

02:20.770 --> 02:21.610
This is a.

02:23.310 --> 02:29.040
Manager only route and this above one is actually admin only routes.

02:29.040 --> 02:32.670
So let's go ahead and say admin only routes.

02:32.820 --> 02:35.400
Yeah, routes make sense and this we have just one.

02:35.400 --> 02:36.480
So route is OC.

02:36.480 --> 02:38.820
So we need to obviously change the route here as well.

02:38.820 --> 02:40.110
This should be manager now.

02:40.110 --> 02:45.870
So slash manager slash user or you can say admin manager because there can be only one for admin.

02:45.870 --> 02:50.610
If you are going to go ahead and use the same route, then it's going to get confused at which should

02:50.860 --> 02:51.210
I run?

02:51.210 --> 02:54.090
And only the first one which it sees, it's going to run that.

02:54.090 --> 02:55.050
So please don't do that.

02:55.260 --> 02:58.260
And here we are going to say this one is for manager only.

02:58.350 --> 03:00.900
And the one this is the one.

03:00.900 --> 03:02.610
So what is going to happen now?

03:02.910 --> 03:04.230
Now what is going to happen?

03:04.230 --> 03:08.520
The custom role obviously is logged in, will inject all the user information.

03:08.520 --> 03:10.200
We'll extract that in the custom role.

03:10.200 --> 03:12.750
In the custom role we are passing on manager.

03:12.750 --> 03:17.580
So this manager will get injected into this array since we are spreading this array right out of the

03:17.580 --> 03:17.880
box.

03:17.880 --> 03:19.890
So it will inject it into this roles array.

03:19.890 --> 03:22.530
So there is one property in the roles array which is manager.

03:22.770 --> 03:29.070
This will check now that this array, which has just one value managers, includes whatever the role

03:29.070 --> 03:30.570
you are saying from the database.

03:30.570 --> 03:36.420
So if you are really manager as according to the database, then this will give me a true value.

03:36.510 --> 03:41.010
So if the value is true, I'm converting that into a false by putting an exclamation sign.

03:41.010 --> 03:43.860
That means, hey, like you get the idea.

03:43.860 --> 03:47.750
I'm not super confuse it, but I hope you get the idea that this is how it is working up.

03:47.760 --> 03:52.110
So if you are if you are not who you are saying, then you'll get a responses error.

03:52.110 --> 03:53.260
Otherwise it's all okay.

03:53.570 --> 03:53.860
Okay.

03:53.970 --> 03:57.420
So let's go ahead and save this one and let's go back on to this one.

03:57.420 --> 03:58.260
Not this one.

03:58.260 --> 03:59.430
Yeah, this is the one.

03:59.520 --> 04:03.630
So now if I go ahead and visit the manager, then I should be getting all the details.

04:03.630 --> 04:04.650
So let's go up here.

04:05.010 --> 04:07.110
I'll go into the logout and hit the send.

04:07.110 --> 04:13.440
So everything is logged out now first let's log in from the to actually I would love to log in from

04:13.440 --> 04:17.310
two and send that and now we are logged in.

04:17.310 --> 04:18.900
Let's try to get all the details.

04:18.900 --> 04:24.300
I am admin so let's go ahead and send this one and I'm getting all the resources available.

04:24.300 --> 04:25.560
So that is fantastic.

04:25.560 --> 04:30.120
Now let's go ahead and log out, send this one and let's log in.

04:30.120 --> 04:33.510
And again, this three is having an extra E.

04:34.530 --> 04:36.780
There we go, triple E, let's go ahead and send.

04:36.780 --> 04:43.020
So I'm now logged in as a three and now let's go ahead and kind of save as this one.

04:43.020 --> 04:52.140
So this one is actually manager, manager, all users save that and this time the route is actually

04:52.260 --> 04:54.420
manager slash users.

04:54.420 --> 04:59.160
If I go ahead and send this one the notice here, this time it says, hey, success is true, but I'm

04:59.160 --> 05:02.640
receiving only one user which is marked as user itself.

05:02.790 --> 05:07.560
Now let's go ahead and sign up another user so that at least we can see some of the data as well.

05:07.680 --> 05:09.720
So we're going to go ahead and mark this one.

05:09.720 --> 05:11.430
We can actually use the post mine itself.

05:11.430 --> 05:16.950
Let's go ahead and use for instead of having an extra three, let's go ahead and use the four.

05:18.060 --> 05:22.380
We are going to go ahead and say this is a user four, I'll use the same password, but I'll choose

05:22.380 --> 05:23.880
a different image this time.

05:23.880 --> 05:29.370
Let's select this one and the image that I'll be using a little bit difficult.

05:29.370 --> 05:30.990
I'll use this logo here.

05:31.260 --> 05:35.040
Let's go ahead and upload that and send this one.

05:36.080 --> 05:38.300
And hopefully this will be uploaded and everything.

05:38.540 --> 05:41.150
So this time all the users are being logged in.

05:41.150 --> 05:46.520
But interestingly, since this should actually change the cookies itself, so it's a great time to check

05:46.520 --> 05:48.140
whether the manager is having all of that.

05:48.140 --> 05:49.340
So let's send this one.

05:49.340 --> 05:55.190
And now we are sending error because our cookie is being replaced by somebody who is a user, not the

05:55.190 --> 05:56.660
admin or the manager.

05:56.990 --> 06:02.030
So let's go ahead and say that you should log out and notice here how Postman is actually helping us

06:02.030 --> 06:03.350
ridiculously well.

06:04.100 --> 06:05.750
And that's why people love Postman.

06:06.170 --> 06:07.640
So we're going to say four.

06:07.670 --> 06:09.110
Let's log in there.

06:10.180 --> 06:11.820
And we shouldn't be logged in with four.

06:11.830 --> 06:13.680
We should be logged in with three to check that.

06:13.690 --> 06:14.320
My bad.

06:15.010 --> 06:19.210
So three with an extra E send that cookies updated hopefully.

06:19.240 --> 06:23.650
Let's go ahead and C manager all user send that and then we go.

06:23.650 --> 06:25.930
We add this time receiving two data.

06:26.140 --> 06:30.910
So this is the first one and this is the second one, not the second one.

06:32.370 --> 06:34.560
So this is the user.

06:34.980 --> 06:37.800
So we are having a photo as an object itself.

06:39.640 --> 06:45.670
And this object seems like, yeah, this is good, but the rapping is not happening.

06:45.670 --> 06:46.480
Great.

06:47.610 --> 06:47.800
Yeah.

06:47.860 --> 06:48.690
Okay, so this.

06:48.690 --> 06:50.320
In this case, this is the two user.

06:50.340 --> 06:50.730
My bad.

06:50.730 --> 06:52.530
I got unnecessarily confused.

06:52.530 --> 06:53.670
So we have got two users.

06:53.670 --> 06:54.480
The first one is this.

06:54.480 --> 06:55.470
Second one is this.

06:55.890 --> 06:56.130
Okay?

06:56.220 --> 07:00.120
So now you can see and understand that how you can define custom roles.

07:00.120 --> 07:05.220
So go ahead and define in your application, your manager, admin, sales, whatever you like to have.

07:05.250 --> 07:07.170
Let's go ahead and catch up in the next video.
