cakephp-3.xcakedc

how to set different auth redirect url for different user group in cakedc plugin cakephp3


Am using cakephp3 and cakedc plugin. I have two user groups , 1 is normal user and other is super user
what i am basically looking for is setting different auth url for different user as both user group have different dashbaord. I tried to hook UsersAuthComponent::EVENT_AFTER_LOGIN .This is my code in eventListener

$helper = new AppView();
$adminDashBoard = $helper->Url->build([
                    'prefix' => 'admin',
                    'controller' =>'users',
                    'action' => 'dashboard',
                    'plugin' => null
                ]);

        $customerDashBoard = $helper->Url->build([
                    'prefix' => 'customer',
                    'controller' =>'customers',
                    'action' => 'dashboard',
                    'plugin' => null
                ]);

        $result = array();
        if($entity['is_superuser'] == 1)
            $result[] = $adminDashBoard;
        else
            $result[] = $customerDashBoard;

        return $result;

I had to create object of AppView as Url builder was not available in EventLister . Above code is working fine but the url that i have appended in result object gets appended in current URL and it becomes like

domain.com/<user's dashboard url in urlencoded format>

but i want it to redirect to user's dashboard url which i had set in eventListner Any help will be appreciated


Solution

  • I can think about 2 options:

    I think option 2 is simple enough to use it, you can extract the common markup from the views into an element and reuse it in both.