<?php

namespace App\Controllers\Auth;

use App\Controllers\BaseController;

use App\Models\User;

class Logout extends BaseController
{
    public function index()
    {
		helper('cookie');
        // Deleting Sessions
		$this->session->remove('login');
		$this->session->remove('logged');
			$this->session->remove('login_token');
			$this->session->destroy();
			$expire = time() - 3600;
            $redirectTarget = trim((string) (service('request')->getGet('redirect') ?? ''));
            $response = redirect()->to($redirectTarget !== '' ? $redirectTarget : 'auth/login')->with('notify_success', 'Logged out ');
			$response
				->setCookie('login', '', $expire, '', '/')
				->setCookie('logged', '', $expire, '', '/')
				->setCookie('login_token', '', $expire, '', '/')
				->setCookie('ci_session', '', $expire, '', '/')
				->setCookie('login', '', $expire, '', '/rewarder')
				->setCookie('logged', '', $expire, '', '/rewarder')
				->setCookie('login_token', '', $expire, '', '/rewarder')
				->setCookie('ci_session', '', $expire, '', '/rewarder');

	        return $response;
    }

}
