Login Cakephp 3 - Redirect Logout

I’m trying to create a Login function to enter the dashboard of a site by ajax, but it usually goes in! The functions work without error and even enter the panel, but redirect to the Login page which is the home page. I’ve already checked the functions and see that the $ this->Auth->setUser(); Always returns null, not if you are actually logging in. Is there a part of the site that also stopped cookie, can this be a global system configuration?

namespace App\Controller;

use App\Controller\AppController;
use Cake\Controller\Component;
use Cake\Controller\Component\AuthComponent;
use Cake\Event\Event;
use Cake\ORM\TableRegistry;

class AccountController extends AppController {
    public function initialize() {
        $this->loadComponent('Auth', [
            'authenticate' => [
                'Form' => [
                    'fields' => ['username' => 'email', 'password' => 'password'],
                    'userModel' => 'Account',
            'loginAction' => [
                'controller' => '/'
            'loginRedirect' => [
                'controller' => 'Account',
                'action' => 'Panel'
            'logoutRedirect' => [
                'controller' => '/'
            'storage' => 'Memory'

    public function index() {
        if ($this->request->is('ajax')) {
            $user = $this->Auth->identify();
            if ($user) {
                echo 'success';
            } else {
                echo 'incorrect';
        else {
            return $this->redirect('/');

Why do you need ajax for login anyway?

Would you elaborate what problem you are facing or what are you trying to achieve in clear words?

I’m sorry, I’m Brazilian. The site will be for an Agency and it requires that most of the functions be by ajax. For example login, forgot my password, sign up for course. They are actions made by modal and can not refresh the page. Also, I can not reload the page just to enter the account that would only change the header of the site or reload to show incorrect message in the modal.