I need to switch user from backend to frontend. Something like that the super admin switches to another user.
I can switch user by Yii::$app->login(…) but it works only in backend or frontend. The problem is in session, because backend and frontend have different sessions.
Two separate Yii applications which share code, mind you
If you want to share sessions between the backend and frontend, you can do so. First thing would be configuring the session cookie so it wasn’t locked down to a single hostname, and then you would have to build an auth piece around it. Not too difficult I suppose.
Or like mentioned you have the option of kicking them to a URL which logs them in to the backend automatically. For instance, generate a unique, one-time log in hash. Lock it down to user agent, IP (depending on requirements), user id, etc. etc. and keep it valid for a short period of time (15 seconds?). Match that user hash to a user ID, log them in, invalidate the hash.