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

ImpersonateManager does not leave the impersonation #77

Open
kejedi opened this issue Mar 19, 2024 · 5 comments
Open

ImpersonateManager does not leave the impersonation #77

kejedi opened this issue Mar 19, 2024 · 5 comments

Comments

@kejedi
Copy link

kejedi commented Mar 19, 2024

I'm on Laravel 11

When I click Leave in the banner, nothing happens.

I've narrowed it down to the ImpersonateManager leave method not working.

Which as to do with the package this package uses.

@kejedi
Copy link
Author

kejedi commented Mar 19, 2024

For now I've just overwritten the route to log the user right out:

Route::get('filament-impersonate/leave', function () {
    Auth::logout();

    return redirect('/login');
})->name('filament-impersonate.leave');

@kejedi
Copy link
Author

kejedi commented Mar 19, 2024

A better workaround for now:

Route::middleware(config('filament-impersonate.leave_middleware'))
    ->get('filament-impersonate/leave', function () {
        $manager = app('impersonate');

        if ($manager->isImpersonating()) {
            $user = $manager->findUserById($manager->getImpersonatorId());

            Auth::quietLogout();

            Auth::quietLogin($user);

            $manager->clear();
        }

        return redirect('/');
    })
    ->name('filament-impersonate.leave');

@AurelDemiri
Copy link

AurelDemiri commented May 3, 2024

I have this issue as well using Laravel 11.

What "fixed" it for me was removing my global scopes (not what I wanted to do) so I just added a check for the leave route:

    protected static function booted(): void
    {
        // Workaround for filament impersonate leave bug.
        if (request()?->route()?->getName() !== 'filament-impersonate.leave') {
            static::addGlobalScope(new ViewableByCurrentUser());
        }
    }

@manbhatia
Copy link

I have this issue as well using Laravel 11.

What "fixed" it for me was removing my global scopes (not what I wanted to do) so I just added a check for the leave route:

    protected static function booted(): void
    {
        // Workaround for filament impersonate leave bug.
        if (request()?->route()?->getName() !== 'filament-impersonate.leave') {
            static::addGlobalScope(new ViewableByCurrentUser());
        }
    }

Worked for me as well. Thanks!

@jszobody
Copy link
Member

Ah, global scopes would make sense. Interesting.

Any thoughts on how this package could provide an option or hook for this? I'm wondering if the leave route should use withoutGlobalScope() somewhere.

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

No branches or pull requests

4 participants