Change loginAction on the fly

Hii there,

I’m trying to redirect my users to the login page when they are not logged in.
However, my app has 2 seperate login forms:

  • The main app (where the regular users will login)
  • The CMS dashboard (for admins n stuff)

This is what I have in the main app’s AppController:

$this->loadComponent('Auth', ['loginAction' => ['plugin'=>null,'controller' => 'Users','action' => 'login'],'logoutRedirect' => ['plugin'=>null,'controller' => 'pages','action' => 'display','home']]);

This redirects the users to the login page of the main app just fine, but this is also the problem, it only redirects the users to the login page of the main app.

So in the AppController for the CMS plugin I added the following code:

$this->Auth->loginAction = [
    'plugin'=>'Kikioboeru/Kikioboeru',
    'controller' => 'Admin',
    'action' => 'login'
];

This however, does nothing, I still get redirected to the main app’s login page instead of the one for the CMS.
So my question is, how can I redirect to the CMS’s login page when somebody tries to use a page in the CMS.

eg. /admin/users should redirect to /admin/login (the login page for the CMS) and /my-account should redirect to /login (the main app’s login page).