In yii2 advanced app I have action with guest check:
public function actionLogin()
{
if (!Yii::$app->user->isGuest)
...
}
I have modified findIdentity($id) in common/models/User from this:
public static function findIdentity($id)
{
return static::findOne(['id' => $id]);
}
to this:
public static function findIdentity($id)
{
if (($model = static::findOne(['id' => $id])) !== null) {
return $model;
} else {
throw new UserException('User not found');
}
}
now, if user is deleted and he is logged in (has session), message ‘User not found’ appears every time, I can not even /logout.
so, how to fix/mofidy isGuest() function? I have a lot of actions on my website that use findIdentity($id) and it is hard to modify them all to check whether user is nulled or not.