Failed when logout

good night, I have trouble with authencticate while users want to logout.
this some code below

in AppController.php

class AppController extends Controller
{
  public function initialize()
    {
        parent::initialize();

        $this->loadComponent('RequestHandler', [
            'enableBeforeRedirect' => false,
        ]);
		//theme nasa
		$this->viewBuilder()->setTheme('Nasa');
		//autentikasi
        $this->loadComponent('Auth', [
			'authenticate' => [
				'Form' => [
					'fields' => [
						'username' => 'Email',
						'password' => 'Password'
					]
				]
			],
			'loginAction' => [
				'controller' => 'Users',
				'action' => 'login'
			],
			//jika tidak sah, maka alihkan
			'unauthorizedRedirect' => $this->referer()
		]);
		//izinkan membaca
		$this->Auth->allow(['beranda', 'view', 'index']);
    }
	
	public function beforeFilter(Event $event)
	{
		$this->Auth->allow(['beranda', 'view', 'index']);
	}
	
	public function beforeRender(Event $event)
	{
		parent::beforeFilter($event);
		$this->set('userInfo', $this->Auth->user());
	}
}

and inside UsersController.php

class UsersController extends AppController
{
  public function beforeFilter(Event $event)
  {
	parent::beforeFilter($event);
	 $this->Auth->allow(['logout', 'add']);
  }
  public function login()
	{
		if ($this->request->is('post')) {
			$user = $this->Auth->identify();
			if ($user) {
				$this->Auth->setUser($user);
				return $this->redirect(['controller' => 'Cafeins', 'action' => 'index']);
			}
			$this->Flash->error(__('Nama pengguna dan password salah, coba lagi'));
		}
	}
	
	public function logout()
	{
		$this->Flash->success('Anda berhasil logout');
		return $this->redirect($this->Auth->logout());
	}

}

while I’m testing to login, the result is succes, but when I’m test to logout, there’s shown error message below

Notice (1024): Undefined property: UsersController::$Flash in C:\xampp\htdocs\alseanasa\src\Controller\UsersController.php on line 113 [CORE\src\Controller\Controller.php, line 388]

Notice (1024): Undefined property: ErrorController::$Auth in C:\xampp\htdocs\alseanasa\src\Controller\AppController.php on line 51 [CORE\src\Controller\Controller.php, line 388]

Warning (512): Unable to emit headers. Headers sent in file=C:\xampp\htdocs\alseanasa\vendor\cakephp\cakephp\src\Error\Debugger.php line=853 [CORE\src\Http\ResponseEmitter.php, line 48]

Warning (2): Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\alseanasa\vendor\cakephp\cakephp\src\Error\Debugger.php:853) [CORE\src\Http\ResponseEmitter.php, line 148]

Warning (2): Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\alseanasa\vendor\cakephp\cakephp\src\Error\Debugger.php:853) [CORE\src\Http\ResponseEmitter.php, line 181]

Warning (2): Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\alseanasa\vendor\cakephp\cakephp\src\Error\Debugger.php:853) [CORE\src\Http\ResponseEmitter.php, line 181]

An Internal Server Error Occurred

Location shown error found at line Flash and Auth below

public function logout()
	{
		$this->Flash->success('Anda berhasil logout');
		return $this->redirect($this->Auth->logout());
	}

and line below

public function beforeRender(Event $event)
 {
	parent::beforeFilter($event);
	$this->set('userInfo', $this->Auth->user());
 }

I hope someone guide me to fix the problem, thanx

First your Flash component is not loaded in your AppController and second one is that you are define logout action in AppControlller like:-

‘logoutRedirect’ => [
‘controller’ => ‘Users’,
‘action’=> ‘login’
],
Please double check your appCopntroller i think your deleting the code.

thanks mr.spadeX for help and guide me. The function logout was successfull running