Welcome Guest, Not a member yet? Register   Sign In
About IonAuth 4 auth System
#1
Sad 
(This post was last modified: 11-02-2019, 10:03 PM by adelbak.)

I'm working on a project based on codeigniter 4 and IonAuth
- I used a IonAuth library as Auth System and included it in BaseController successfully using:
$this->ionAuth = new \IonAuth\Libraries\IonAuth();
- After that i make my Auth controller extends BaseController without problems.

The question is:

When I check the login in __construct function of any controller I get Call to a member function loggedIn() on null error.
-  when i add $this->ionAuth = new \IonAuth\Libraries\IonAuth(); in __construct function even though I called him in BaseController before, Error is gone but loggedIn() don't work Huh .


PHP Code:
<?php namespace App\Controllers;

use 
App\Models\DashboardModel;

class 
Dashboard extends BaseController
{
    
    protected 
$Dashboard;

    public function 
__construct()
    {
    
    $this->dashboardModel = new DashboardModel();
            $this->ionAuth = new \IonAuth\Libraries\IonAuth();        

        if (!
$this->ionAuth->loggedIn())
        {
            return redirect()->to(base_url().'/auth/login');
        }
        
    }    
    
    public function indexOne()
    {
        return view('pages/indexOne');       
    
}

    public function indexTwo()
    {
        return view('pages/IndexTwo');       
    
}
    
    public function indexThree()
    {
        return view('pages/indexThree');       
    
}




To avoid the error I have to call if (!$this->ionAuth->loggedIn()) at all controll methodes like this:
PHP Code:
<?php namespace App\Controllers;

use 
App\Models\DashboardModel;

class 
Dashboard extends BaseController
{
    
    protected 
$Dashboard;

    public function 
__construct()
    {
    
    $this->dashboardModel = new DashboardModel();
    }    
    
    public function indexOne()
    {        
    
    if (!$this->ionAuth->loggedIn())
        {
            return redirect()->to(base_url().'/auth/login');
        }
        return view('pages/indexOne');       
    
}

    public function indexTwo()
    {
    
    if (!$this->ionAuth->loggedIn())
        {
            return redirect()->to(base_url().'/auth/login');
        }    
        return view('pages/IndexTwo');       
    
}
    
    public function indexThree()
    {
    
    if (!$this->ionAuth->loggedIn())
        {
            return redirect()->to(base_url().'/auth/login');
        }    
        return view('pages/indexThree');       
    
}




I think that's ugly way, any Solutions please??
Thanks.
Reply


Messages In This Thread
About IonAuth 4 auth System - by adelbak - 11-02-2019, 10:00 PM
RE: About IonAuth 4 auth System - by Poetawd - 11-09-2019, 02:08 PM
RE: About IonAuth 4 auth System - by macruzgi - 11-13-2019, 10:55 AM
RE: About IonAuth 4 auth System - by XTAZ - 11-12-2019, 01:16 PM
RE: About IonAuth 4 auth System - by cseon - 11-27-2019, 12:59 AM



Theme © iAndrew 2016 - Forum software by © MyBB