Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When I leave the impersonation, it logs out #165

Open
adantart opened this issue Aug 19, 2022 · 3 comments
Open

When I leave the impersonation, it logs out #165

adantart opened this issue Aug 19, 2022 · 3 comments

Comments

@adantart
Copy link

adantart commented Aug 19, 2022

Laravel Framework 9.19.0

I have tried using the link generated by route('impersonate.leave')
and also with my own controller method and using manually: Auth::user()->leaveImpersonation();

But both ways redirects me to the login page, since it loses the authentication of the original user.

I tried (reading some other issues) using Route::middleware(['auth:web',]) instead of auth:sanctum.
And also add this

Event::listen(\Lab404\Impersonate\Events\TakeImpersonation::class,
            function(\Lab404\Impersonate\Events\TakeImpersonation $event) {
                session()->put('password_hash_sanctum', $event->impersonated->getAuthPassword());
            });
        Event::listen(\Lab404\Impersonate\Events\LeaveImpersonation::class,
            function(\Lab404\Impersonate\Events\LeaveImpersonation $event) {
                session()->put('password_hash_sanctum', $event->impersonator->getAuthPassword());
            });

But problem persists...

Any ideas ?

@Arne1303
Copy link

This might be #162, there is a workaround I'm the comments over there which you could test

@adantart
Copy link
Author

Unfortunately, it still logs out when I leave impersonation

@henriquecm
Copy link

I had this problem on this library, then I looked for another one, but unfortunately it had the same problem, but after a while I found a solution, so it might work on this one too.

$impersonate = Auth::user()?->impersonate();
$user = $impersonate->getImpersonator();
$impersonate->leave();

Auth::guard('sanctum')->setUser($user);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants