Two different login for 2 controller using one users table

https://book.cakephp.org/5/en/tutorials-and-examples/cms/authentication.html
Follow this link to add login in process in cakephp5.
Now i need different login for users and admins controller.
after auto session time out i want to show them their respective login page.

How are you planning to determine what is “their” login page after the session has timed out and you no longer know who “they” are?

I’m facing this same issue in cakephp5.
in cakephp 3 below code works for me. Want this in cakephp5 but not get any. Do you have any solution?

$Current_controller = $this->getRequest()->getParam(‘controller’);

    if ($Current_controller == 'Appadmins') {
        $this->loadComponent('Auth', [
            'authenticate' => [
                'Form' => [
                    'fields' => [
                        'username' => 'email',
                        'password' => 'password'
                    ]
                ]
            ],
            'loginAction' => [
                'controller' => 'Appadmins',
                'action' => 'login'
            ],
            'logoutRedirect' => [
                'controller' => 'Appadmins',
                'action' => 'logout',
            ]
        ]);
    }


    if ($Current_controller == 'Users') {
        $this->loadComponent('Auth', [
            'authenticate' => [
                'Form' => [
                    'fields' => [
                        'username' => 'email',
                        'password' => 'password'
                    ]
                ]
            ],
            'loginAction' => [
                'controller' => 'Users',
                'action' => 'index',
                '?' => ['type' => 'login']
            ],
            'logoutRedirect' => [
                'controller' => 'Users',
                'action' => 'logout',
            ]
        ]);
    }

$Current_controller = $this->request->getParam(‘controller’);

I am not sure, if this is your question/problem, but you will get the controller name.

1 Like

$Current_controller = $this->getRequest()->getParam(‘controller’);

if ($Current_controller == 'Appadmins') {
        $this->loadComponent('Auth', [
            'authenticate' => [
                'Form' => [
                    'fields' => [
                        'username' => 'email',
                        'password' => 'password'
                    ]
                ]
            ],
            'loginAction' => [
                'controller' => 'Appadmins',
                'action' => 'login'
            ],
            'logoutRedirect' => [
                'controller' => 'Appadmins',
                'action' => 'logout',
            ]
        ]);
    }


    if ($Current_controller == 'Users') {
        $this->loadComponent('Auth', [
            'authenticate' => [
                'Form' => [
                    'fields' => [
                        'username' => 'email',
                        'password' => 'password'
                    ]
                ]
            ],
            'loginAction' => [
                'controller' => 'Users',
                'action' => 'index',
                '?' => ['type' => 'login']
            ],
            'logoutRedirect' => [
                'controller' => 'Users',
                'action' => 'logout',
            ]
        ]);
    }

Above code i’m using in cakephp3. Need to know how can i do the same in cakephp5 as Auth component no more in cakephp5.