Git Product home page Git Product logo

Comments (3)

jszobody avatar jszobody commented on September 22, 2024 1

Multi-tenancy can be implemented in 100 different ways. I don't know how yours works, I can't tell you what needs to be handled.

The underlying impersonate package does fire some events when impersonation happens, maybe you can listen for those events and wire up the appropriate tenant that way?

https://github.com/404labfr/laravel-impersonate?tab=readme-ov-file#events

from filament-impersonate.

altomar avatar altomar commented on September 22, 2024

in my case, I have 2 panels, one with multi-tenancy and the other without. When I impersonate a user that does not belong to a tenant, I get memory leak. Then I added the user to a tenant and then it worked as normal.

from filament-impersonate.

mansoorkhan96 avatar mansoorkhan96 commented on September 22, 2024

Hey @altomar

I did not hit the memory issues but here is what worked for me in case it helps you.

In your web.php, define a custom route for impersonate.

Route::get('/impersonate/{user}', ImpersonateController::class)->name('impersonate');

Create the ImpersonateController.

use App\Models\User;
use Filament\Support\Concerns\EvaluatesClosures;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use STS\FilamentImpersonate\Concerns\Impersonates;

class ImpersonateController extends Controller
{
    use EvaluatesClosures; // We need this trait in order use the impersonate feature from the plugin
    use Impersonates;

    public function __invoke(Request $request, User $user): RedirectResponse
    {
        abort_unless(auth()->check() && auth()->user()->is_admin, 403);

        return $this->impersonate($user); // we are using the function from the plugin.
    }
}

Finally in UserResource, pass the custom url to Impersonate action.

->actions([
        Impersonate::make()
            ->url(fn (User $record) => route('impersonate', $record)),
])

from filament-impersonate.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.