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:
@Steve_OH I got it working with this middleware code. My Team model is Company and tenant login url is dashboard/login
Jump to solution
18 Replies
Steve_OH
Steve_OH2mo ago
What are you using to redirect them? Is it a middleware?
mohdaftab
mohdaftab2mo ago
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
mohdaftab
mohdaftab2mo ago
I have these middleware in DashboardPanel
No description
mohdaftab
mohdaftab2mo ago
this is VerifyNotAdmin middleware
No description
Steve_OH
Steve_OH2mo ago
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
mohdaftab
mohdaftab2mo ago
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 ?
Steve_OH
Steve_OH2mo ago
Yeah sorry been busy, will post later
mohdaftab
mohdaftab2mo ago
thank you so much
Steve_OH
Steve_OH2mo ago
Steve_OH
Steve_OH2mo ago
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
mohdaftab
mohdaftab2mo ago
Thank you so much, I will try to use the required part from this code.
Steve_OH
Steve_OH2mo ago
Any luck?
mohdaftab
mohdaftab2mo ago
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
Steve_OH
Steve_OH2mo ago
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
mohdaftab
mohdaftab2mo ago
I removed all the code for later as it was keeping me from working on other tasks, but I will share it by tomorrow.
Want results from more Discord servers?
Add your server