Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

Auth session not pass to security plugin beforeDispatch function

Hi All,

I have to deploy project to centos server and i have problem with security plugin.

In class SecurityPlugin and function beforeDispatch i have to call auth session that set from Login function like this.

Login function

$this->session->set('auth', array( 'accountno' => $userInfo['partnerAccountNo'], 'loginname' => $userInfo['firstName'], 'last_name' => $userInfo['lastName'], ));

And show that in beforeDispatch, but it can not get session

beforeDispatch function

$auth = $this->session->get('auth'); var_dump($auth);
if (!$auth){ $role = 'Guests'; } else { $role = 'Users'; }

the $auth variable show null after var_dump.

Pls help me, thanks


Anyone pls help me


You did initialize session within $di?

$di->setShared('session', function () {
    $session = new SessionAdapter();

    return $session;

Also, you did attach the plugin to the eventsManager and eventsManager to dispatcher (and you did create a method beforeDispatch in SecurityPlugin.php)?

        $di->set('dispatcher', function() use ($config) {

            $eventsManager = new EventsManager();
            $eventsManager->attach('dispatch:beforeDispatch', new SecurityPlugin);

            $dispatcher = new Dispatcher();


            return $dispatcher;

Did you try with the beforeExecuteRoute() event instead of beforeDispatch?

Also did you register the namespace for the plugin in the loader (and then used that namespace)?

        'Plugins'   => $config->application->pluginsDir,