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
#11

See may be help you https://github.com/codeigniter4/shield/d...nt-5768371
Reply
#12

@sknair143 We made changes to cover this feature in the PR below.
Please review this if you can.

https://github.com/codeigniter4/shield/pull/790
Reply
#13

(08-17-2023, 06:46 AM)datamweb Wrote: @sknair143 We made changes to cover this feature in the PR below.
Please review this if you can.

https://github.com/codeigniter4/shield/pull/790

Thanks !, But could you please help me to implement this on my project. Can you give me the steps to do please.
Reply
#14

If I understand well, here is my solution to handle admin and portal namespaces.
Here is before method from my Admin filter:
PHP Code:
    public function before(RequestInterface $request$arguments null)
    {
        if (! $request instanceof IncomingRequest) {
            return;
        }

        if (auth()->user()->inGroup('superadmin''admin')) {
            return;
        }

        return redirect()->to('login');
    

And here is before method from my Portal filter:

PHP Code:
    public function before(RequestInterface $request$arguments null)
    {
        if (! $request instanceof IncomingRequest) {
            return;
        }

        if (auth()->user()->inGroup('customer')) {
            return;
        }

        return redirect()->to('login');
    

As you can see I'm using group customer for my portal users. 
Here is updated redirects, loginRedirect and registerRedirect methods in Shield auth config.

PHP Code:
    public array $redirects = [
        'register'    => 'portal',
        'login'      => 'portal',
        'logout'      => 'login',
        'force_reset' => '/',
    ]; 

PHP Code:
    public function loginRedirect(): string
    
{
        $url auth()->user()->inGroup('customer')
            setting('Auth.redirects')['login']
            site_url(ADMIN_AREA);

        return $this->getUrl($url);
    

PHP Code:
    public function registerRedirect(): string
    
{
        $url auth()->user()->inGroup('customer')
            setting('Auth.redirects')['register']
            site_url(ADMIN_AREA);

        return $this->getUrl($url);
    
Reply
#15

@sknair143 This feature was added to the Shield. Use the develop branch.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB