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

impersonate for users in multi-tenancy project with custom domains #168

Open
maherelgamil opened this issue Sep 7, 2022 · 2 comments
Open

Comments

@maherelgamil
Copy link

Hey,

I have multi-tenancy project with custom domains,

So, how can I impersonate users from other domains?

Thanks

@ju5t
Copy link

ju5t commented May 10, 2023

We do this too, but we don't have a strict requirement to switch domains when we impersonate a user. For Spatie's multi tenancy solution you can use middleware to set the tenant. This assumes you have a relation set on your User-model.

public function handle(Request $request, Closure $next): mixed
{
    if (app('impersonate')->isImpersonating()) {
        auth()->user()->tenant->makeCurrent();
    }

    return $next($request);
}

We're not using this in production yet but I have not found any issues with it.

@DarrenSingh
Copy link

We do this too, but we don't have a strict requirement to switch domains when we impersonate a user. For Spatie's multi tenancy solution you can use middleware to set the tenant. This assumes you have a relation set on your User-model.

public function handle(Request $request, Closure $next): mixed
{
    if (app('impersonate')->isImpersonating()) {
        auth()->user()->tenant->makeCurrent();
    }

    return $next($request);
}

We're not using this in production yet but I have not found any issues with it.

Are you able to further explain how you're accomplishing this?

I'm looking to accomplish something similar, except for a specific subdomain not a tenant. I am trying to impersonate a member guard class in my subdomain from a user class on my main domain

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