Refresh session data / identity object

@MDebus
Thu, 05 Sep 2024 13:32:57 +0000

It doesn’t seem to be that easy to keep the session data up to date.

The Authentication Component’s setIdentity() method doesn’t seem to do what it’s supposed to do, even though it’s described here:

https://book.cakephp.org/authentication/3/en/migration-from-the-authcomponent.html#checking-identities

In this code snipet from docs you can read the entity from database and set it as identity, but it’s not working…

Here is a working code, although it’s not really nice to do it this way:

public function beforeFilter(EventInterface $event)
{
        parent::beforeFilter($event);

        if ($this->Authentication->getIdentity()) {
            $user = $this->fetchTable('Users')->get($this->Authentication->getIdentity()->get('id'),
                ['finder' => 'authenticatedUser']);
            $session = $this->request->getSession();
            $session->write('Auth', $user);
        }
}

Any other solution to solve that problem?