User identity data lost in 2.0.47

My app is work properly in 2.0.43.
After I update to 2.0.47 user identity data lost after successful login (login properly, redirect and user identity data lost, in debugger User is guest).
I suppose that metod findIdentity() of User class must work in different way in 2.0.47.


public static function findIdentity($id)
                $connection0 = Yii::$app->db;
                $command0 = $connection0->createCommand("SELECT id_osoby ..cutted.. WHERE id_osoby = :id_osoby AND other_conditions ");
                $command0->bindValue(':id_osoby', $id);
                $user = $command0->queryOne();

                if (isset($user) && $user['id_osoby'] == $id) {
                $Zgloszenia = Zgloszenia::find()
                    ->where("id_osoby = :id_osoby", [":id_osoby" => $id])
                    ->andwhere("status_konta > 0")

                if (isset($Zgloszenia))
                return new static($Zgloszenia);

        return null;

Any suggestion how to change function findIdentity() ?

1 Like

The findIdentity function in User model Class in the advanced template is as below:

    public static function findIdentity($id)
        return static::findOne(['id' => $id, 'status' => self::STATUS_ACTIVE]);

This seems like custom code.

What’s the reason for this code in the first place? Yii2’s implementation of findIdentity in yii\web\IdentityInterface should work absolutely fine for the returning the given user. If you’re attempting to implement additional functionality just separate it into another method against the User class (or however you wish) and ensure you’re returning a user object from your query.