yii2 login user manualy with getting user and password from ajax

i send mobile number as username and active_code as password from view file(ajax) to action with jquery and i want login user with this data.

this code is my action:

 $identity = \common\models\User::findOne(["username"=>$mobile]);


it is worked but after page refreshed, it seems user not logged in!

is any way to do this?

Would you please elaborate your issue a little more in details?

even though its very unlikely, perhaps try setting a duration for the identity like so

Yii::$app->user->login($identity, 3600 * 60);