Conditional Multi-Tenancy Panel Redirect
Well hello there! I have a panel with Multi-Tenancy in my app. When a user that has not yet any tenants clicks the link to the panel, he will get a 404. Now I can configure the panel with a tenant registration page. Now instead of a 404 the user will get directed to that creation page. However, I don't want all users to be able to create a tenant. So I adjusted my Policy class for the tenant model. Now the users get a 404 again.
Is there a possibilty to configure conditional redirects? Admin users should be able to create a new model, while other users should see a page that informs them to "ask an admin to have them added to a tenant"
3 Replies
I don't have a solution yet, but just want to say that I'm in the same boat here. Administrators manage the tenants and associations between users and tenants. I am wanting to redirect users who log in and do not yet have any tenant profiles, to a landing page that I can customize accordingly. "You do not have any active profiles yet" or something similar.
My most recent attempt to resolve this was through
->tenantMiddleware()
- where I was hoping I could intercept and redirect accordingly, but it seems that the middleware doesn't get executed at all, which makes sense since it would only be reached after tenancy is confirmed.Once you've enasbled tenancy on a panel, all the routes get configured with the tenant ID built-in. Perhaps you could register a separate panel without tenancy (
WelcomePanelProvider
at /welcome
, for example), and using a non-tenant middleware on the main panel to redirect users without a tenant to that panel instead?Yes, what you've described is along the lines of what I was going to attempt next. I think it'll work.