I have followed the tutorials on the official site but The redirect part is not working for the first time
Step 1 : go to users/login and login with correct credentials.
Result : Login successful but redirected to pages/home instead of articles/index.
Step 2 : again go to users/login and login with correct credentials.
Result : Redirecting properly to articles/index (session is logged in)
How may I fix this?
It seems that it was working fine before I tried the authorisation part.(not sure). But I have commented all authorisation part. Still not fixed.
Anything I am missing?
AppController
<?php
namespace App\Controller;
use Cake\Controller\Controller;
use Cake\Event\Event;
class AppController extends Controller
{
public function initialize()
{
$this->loadComponent('Flash');
$this->loadComponent('Auth', [
// 'authorize' => ['Controller'], // Added this line
'loginRedirect' => [
'controller' => 'Articles',
'action' => 'index'
],
'logoutRedirect' => [
'controller' => 'Pages',
'action' => 'display',
'home'
]
]);
}
//public function isAuthorized($user)
//{
// // Site Admin can access every action
// if (isset($user['role']) && $user['role'] === 'admin') {
// return true;
// }
//
// // Default deny
// return false;
//
//}
public function beforeFilter(Event $event)
{
$this->Auth->allow(['index','display']);
}
}
?>
UPDATE
If I directly access the login URL i.e. users/login and then login, It works perfectly. However I have a button in my pages/home page which redirects to the users/login page on click. By using this route via the button, If I login, I am facing the issue.
Note: If viewed the session information with the debugKit, It shows redirect to /
button code in home.ctp file
<?php echo $this->Html->link('<span class = "glyphicon glyphicon-log-in"></span> Login',['controller' => 'users', 'action' => 'login'],['escape' => false]);?>
Any ideas?