I have made a simple action 'Act as this user' for aplication adminis. It looks like this:
-
logout current user
-
log in as given user
-
set 'shared_cookie' based on new current user ( \App\Auth\AuthUser::getUserData() gets prepared data based on Auth::user() )
public function actAsUser(Request $request, $id) { Auth::guard()->logout(); $request->session()->invalidate(); \Cookie::queue(\Cookie::forget('shared_cookie')); $id = \Hashids::decode($id)[0]; $user = User::find($id); Auth::guard()->login($user); \Cookie::queue(\Cookie::make('shared_cookie', \App\Auth\AuthUser::getUserData(), config('session.lifetime') , null, config('app.cookie_shared_domain'), false, false)); }
It should work, but not quite. The result is random!
'shared_cookie' is always set properly, but in the next request, Auth::user() randomly returns old or new user.
Sometimes it seems, that it depends from the user, but not quite..
Any ideas? Please help!
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire