Welcome Guest, Not a member yet? Register   Sign In
Using shield, How i can redirect to separate url if the user not in admin group
#1

Hello,
I'm working with codeigniter shield package for authorization and i want to restrict  normal user to access the administration controllers which is not in admin group. but everything works perfect, it redirects to index page if the user not in admin group. but i want to to redirect them to seperate page instead of redirecting to the index page.

Below is my code in Routes.php 

Code:
$routes->group("admin", ["namespace" => "\Admin\Controllers", "filter" => "group:admin"], static function ($routes) {



    $routes->get('entities', 'Entities::index');
    $routes->post('entities/create', 'Entities::create');

});


How i can redirect to seperate page ?

Thanks
Reply
#2

CodeIgniter 4 Shield User Guide - Authentication Flow
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#3

We have the following solution to transfer the user if he belongs to a certain group or permission, after login. But I think that is not what you mean.

https://codeigniter4.github.io/shield/cu...n-redirect

What I understand is that you want the following feature to be added to the shield.
https://github.com/codeigniter4/shield/p...1375755217
Reply
#4

(This post was last modified: 08-16-2023, 12:09 AM by sknair143.)

I tried afterPermissionDenied but that does not work

Everything works and showing the error " You do not have the necessary permission to perform the desired operation." if the user is not admin and accessing the administrator routes. but i want to change the redirect index to other routes.
Reply
#5

(08-16-2023, 12:08 AM)sknair143 Wrote: I tried afterPermissionDenied but that does not work

This feature has not been added to the shield yet, as we have not had a request.
Reply
#6

(08-15-2023, 11:26 PM)datamweb Wrote: We have the following solution to transfer the user if he belongs to a certain group or permission, after login. But I think that is not what you mean.

https://codeigniter4.github.io/shield/cu...n-redirect

What I understand is that you want the following feature to be added to the shield.
https://github.com/codeigniter4/shield/p...1375755217

(08-16-2023, 01:30 AM)datamweb Wrote:
(08-16-2023, 12:08 AM)sknair143 Wrote: I tried afterPermissionDenied but that does not work

This feature has not been added to the shield yet, as we have not had a request.


How i can do this another way i just using  filter=>"group:admin" inb routes
Reply
#7

(08-16-2023, 01:33 AM)sknair143 Wrote: How i can do this another way i just using  filter=>"group:admin" inb routes

See:

https://github.com/codeigniter4/shield/p...1046458048

By changing:

https://github.com/codeigniter4/shield/b...er.php#L41
Reply
#8

(08-16-2023, 01:46 AM)datamweb Wrote:
(08-16-2023, 01:33 AM)sknair143 Wrote: How i can do this another way i just using  filter=>"group:admin" inb routes

See:

https://github.com/codeigniter4/shield/p...1046458048

By changing:

https://github.com/codeigniter4/shield/b...er.php#L41


So if i change directly to the core file it will get removed if future updates come in the package right ?
Reply
#9

Yes exactly, for this reason it is not recommended to do this.
Reply
#10

(08-16-2023, 02:01 AM)datamweb Wrote: Yes exactly, for this reason it is not recommended to do this.
So there is any other solution ?
Reply




Theme © iAndrew 2016 - Forum software by © MyBB