404labfr / laravel-impersonate

Laravel Impersonate is a plugin that allows you to authenticate as your users.
https://marceau.casals.fr
1.95k stars 203 forks source link

No leaves user impersonation when go to route('impersonate.leave') #179

Closed nachete1987 closed 1 year ago

nachete1987 commented 1 year ago

I am getting a strange behavior, when I try to impersonate a user everything works OK, but when I try to stop impersonating it, only the redirection to the leave_redirect_to path occurs but the impersonated user is kept, I can't get out to the initial user. The strange thing is that in the non-production environment it works but not in production. I use Jetstream and fortify as well as the auth guard web.

Someone with the same problem?

drbyte commented 1 year ago

It would be helpful if you create a simple demo application which demonstrates this problem. ie: a stripped-down version of your application, with only the essentials needed for this problem to occur. (or you could share your complete application code in a github repository, if you prefer)

That will allow us to look at your code and see where the problem may be. And/or run the application to debug it to find where the problem is.

nikspyratos commented 1 year ago

@nachete1987 Are you using global scopes on the User model? I've noticed this in an application where global scopes get applied, as they are applied in the ImpersonationManager. So if your impersonated user has any scope limiting them, the leave will throw an exception and try to load the page as before.

This workaround may be of use.

nachete1987 commented 1 year ago

Oh my god it works!!!!!! Thanks a lot!!! I have a global scope in user model and with this workaround I have been able to impersonate and logout impersonated user successfully.