I am using the Auth Component to set the redirects on Login and Logout:
$this->loadComponent('Auth', [
'loginRedirect' => [
'controller' => 'Adresses',
'action' => 'index'
],
'logoutRedirect' => [
'controller' => 'Pages',
'action' => 'display',
'home'
],
'authenticate' => [
'Form' => [
'fields' => ['username' => 'email']
]
],
'authorize' => 'Controller',
]);
Now I want the User to get redirect on different pages accordance with their role,which works well so far:
if ($this->Auth->user('role') == 'admin') {
return $this->redirect([
'controller' => 'adresses',
'action' => 'adminindex'
]);
}
} elseif ($this->Auth->user('role') == 'user') {
return $this->redirect([
'controller' => 'adresses',
'action' => 'index'
]);
}
Now I want to redirect the different roles to the requested links.And for that I am using:
return $this->redirect($this->Auth->redirectUrl());
Which works only for request like view and edit.Otherwise It is falling back to the Auth Component redirect , which I do not want.
How can I accomplish that I have my regular Fallback in the Auth Component (App Controller) my Role switcher and also the redirect, when views are requested and the user/admin is not logged in already.
For that i tried:
if(!empty($this->Auth->redirectUrl())){
}
Which doesn't working.Any idea would be appreciated.