Ion Auth + Codeigniter logged_in always redirects to login

760 Views Asked by At

I am currently using Codeigniter 3.1.2 with Ion Auth. I can login and view my dashboard page, however if I attempt to view another page that requires the user to be logged in, such as the customer page I am always redirected to the login page.

Controller

public function __construct(){
    parent::__construct();
    $this->load->library('form_validation');
    $this->load->library('session');
    $this->load->helper('form');
    $this->load->helper('url');
    $this->load->model('CRUD');

    if (!$this->ion_auth->logged_in()) {
        redirect('User/index');
    }
}

public function index(){
    $this->load->helper('form');
    $this->load->view('login');
}

public function dashboard(){
    $this->load->view('dashboard');
}

public function customerPage(){
    $data['customer'] = $this->CRUD->getCustomers();
    $this->load->view('customer', $data);           
}

public function materialPage(){
    $data['material'] = $this->CRUD->getMaterials();
    $this->load->view('material', $data);

}

Thanks, CHTRK

1

There are 1 best solutions below

0
On
public function __construct(){
parent::__construct();
$this->load->library('form_validation');
$this->load->library('session');
$this->load->helper('form');
$this->load->helper('url');
$this->load->model('CRUD');

if (!$this->ion_auth->logged_in()) {
    redirect('User/index');
}

"!$this->ion_auth->logged_in()" use this outside the constructor because it will run every time. you should create a different method to call every time in the methods. don't use it for index