AdminPanelProvider auth() returns null.

I am trying to dynamically build a tenant menu based on tenant configuration data. However that is based on what the current user is assigned in the org. However I cannot access the current user via the auth() provider. I am also having issues access the current TenantID. The only way I can seem to access the current user is with this code. Please note that this is just some mock code to determine
->tenantMenuItems([Org::getTenantMenuItems()])

static public function getTenantMenuItems(): array {

// THIS DOES NOT WORK, auth()->user() is null
$user = fn() => dd(auth()->user());
$user();

// THIS WORKS, but filament:Serving returns void
$user = Filament::serving(fn() => dd(Filament::getTenant()));

return [];
}
->tenantMenuItems([Org::getTenantMenuItems()])

static public function getTenantMenuItems(): array {

// THIS DOES NOT WORK, auth()->user() is null
$user = fn() => dd(auth()->user());
$user();

// THIS WORKS, but filament:Serving returns void
$user = Filament::serving(fn() => dd(Filament::getTenant()));

return [];
}
'
Solution:
// THIS DOES NOT WORK, auth()->user() is null
Yeah makes sense. ServiceProviders run way before any user is authenticated. You could use a middleware to modify that part of the app. You should be able to access the current panel by Filament::getCurrentPanel() and set the tenant menu items....
Jump to solution
2 Replies
Solution
Dennis Koch
Dennis Koch11mo ago
// THIS DOES NOT WORK, auth()->user() is null
Yeah makes sense. ServiceProviders run way before any user is authenticated. You could use a middleware to modify that part of the app. You should be able to access the current panel by Filament::getCurrentPanel() and set the tenant menu items.
darcy1368
darcy1368OP11mo ago
Ok, fair enough. I'll give that a try and see what happens That worked
Want results from more Discord servers?
Add your server