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 [];    
}

'
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.
Was this page helpful?