F
Filamentβ€’11mo ago
Sjoerd24

User not linked to tenant > redirect to new tenant page

So the question if pretty straighforward, after a new user has registered in my Filament panel he/she is not yet linked to a tenant (if they are invited this is already arranged,but not every user is invited of course). The problem is I need to redirect a user that isn't linked to a tenant to go to (in my case) "clinic/new". I think the code should be something like this:
user is logged in but not linked to a tenant, redirect to register clinic page
if (!Filament::getTenant() && $request->url <> url('/clinic/new')) {
return redirect('/clinic/new');
}
user is logged in but not linked to a tenant, redirect to register clinic page
if (!Filament::getTenant() && $request->url <> url('/clinic/new')) {
return redirect('/clinic/new');
}
But where do I put this code? Stupid question probably but I cant figure it out. I tried a middleware but that doesn't seem to work, I suspect an 404 error is given earlier in the chain. Anybody any tips? btw: I use Shield with spatie permissions Teams for authentication.
Solution:
Ok fixed it, the policy of my tenant (the create) you have to make an exception for new users. Now everything works. πŸ₯²
Jump to solution
3 Replies
Sjoerd24
Sjoerd24OPβ€’11mo ago
I now tried user model (but from bools you can't do a redirect I found out :P) And I tried the middleware again, because I think that should be then best but it doesn't seem to excecute. I think the 404 is occuring because the user is not linked to any tenant. How can I intercept before that point and do a redirect? Strange thing is that i now remember that in the beginning this was already working, but I think after spatie team/shield it stopped working. Is it a permissions problem? If i log in as a new user and go to clinic/new that is accessible (just a standard register tenant page made with the docs) Reading everything again probably my question is unclear, to put it simpler: how can I forward new users to the TenantRegistration page? Where is the best place to do this?
Sjoerd24
Sjoerd24OPβ€’11mo ago
Ok for someone reading this later, I found the problem (not yet a fix), this code is responsible for the auto redirect:
protected function redirectToTenantRegistration(Panel $panel): RedirectResponse
{
if (! ($panel->hasTenantRegistration() && filament()->getTenantRegistrationPage()::canView())) {
abort(404);
}

return redirect($panel->getTenantRegistrationUrl());
}
protected function redirectToTenantRegistration(Panel $panel): RedirectResponse
{
if (! ($panel->hasTenantRegistration() && filament()->getTenantRegistrationPage()::canView())) {
abort(404);
}

return redirect($panel->getTenantRegistrationUrl());
}
Problem with me is that new user don't yet have a role, because with spatie permissions Teams the roles are linked to a clinic (tenant). If i make a role with clinic_id = 0 then you can access the tenant registration, but the redirect is still not working.. But now I know better what the problem is. PHPdebugbar show that the following gates are refusing (see image) . Now I have to find way to fix that issue πŸ™‚
No description
Solution
Sjoerd24
Sjoerd24β€’11mo ago
Ok fixed it, the policy of my tenant (the create) you have to make an exception for new users. Now everything works. πŸ₯²
Want results from more Discord servers?
Add your server