Multi tenancy sub-domain redirection problem
Hello,
I have multiple tenants attached to a user and I am using wildcard subdomains for each tenant url.
Everything works good but the issue with redirection after logging in has a little problem which I think should be an easy fix but I am struggling to figure it out.
Here are the details:
User is attached to 2 tenants with slugs company-1 and company-2
subdomain is company-1.domain.com and company-2.domain.com
I have setup default tenant and latest tenant in User model.
so the issue is when a user tries to login using company-2.domain.com they get redirected to company-1.domain.com/dashboard where user has to switch to company 2 to access it.
I need a solution to redirect user to the same subdomain which they used to login.
Thank you so much in advance.
Solution:Jump to solution
@Steve_OH I got it working with this middleware code. My Team model is Company and tenant login url is dashboard/login
18 Replies
What are you using to redirect them? Is it a middleware?
Hi, @Steve_OH well I have 2 panels, 1 for admin and 1 for tenants as dashboard
I am using middleware but somehow the Filament::getUrl() always gets the company-1 url even if I am logging in using compani-2.domain.com/dashboard/login page
I have these middleware in DashboardPanel
![No description](https://cdn.answeroverflow.com/1263501288985858169/image.png)
this is VerifyNotAdmin middleware
![No description](https://cdn.answeroverflow.com/1263501387707191316/image.png)
I use a similar system and have middleware for the redirect. I don’t see anything in this middleware for the tenancy redirection though. It must be in your panel configuration
there isn't anything for redirection
could you please share your middleware code so I can also add the redirection?
Thank you
@Steve_OH is it possible to please share the code ?
Yeah sorry been busy, will post later
thank you so much
Here's the file
Of course I have some other things going on here that you probably don't need. my tenancy is based on their assigned organization and I have 3 panels, one is separated on whether they are that organization's client or not. The subdomain in my case is only used for that third tier
Thank you so much, I will try to use the required part from this code.
Any luck?
Hi, I used some methods from this code by taking the $request->getHost() and extracting subdomain from it, matched the subdomain from the tenant subdomain and used redirect but the main issue when I click on login button it simply sends requests to the 1st tenant attached to the user instead of the tenant which I used to login.
So the middleware still thinks it is the same subdomain where it is redirecting to.
I am testing different methods to see how can I make this work and will share it here.
Thank you
I'm not sure I follow, this should impact the user that is currently running the page, not someone else. Share your code if you don't mind
I removed all the code for later as it was keeping me from working on other tasks, but I will share it by tomorrow.