ksorbo's avatar
Level 8

Cannot access authenticated user from within filament admin panel provider

When I use the following code:

$user = auth()->user();

from within the panel method of the AdminPanelProvider, I get null, even when the user is logged in. Here is my user model declaration:

class User extends Authenticatable implements FilamentUser

How do I access the currently logged in user from there?

0 likes
5 replies
cookie's avatar

Give it a shot using Auth::user() or $request->user() or just clear your Cache. :)

ksorbo's avatar
Level 8

Turns out it is not possible. You can only access the logged in user via a callable.

tisuchi's avatar

@ksorbo Can you try this?

$user = \Filament\Facades\Filament::auth()->user();

According to my knowledge, it ensures you're pulling the user from Filament's admin panel authentication context, not the default Laravel guard.

jaseofspades88's avatar

Why? What are you trying to achieve in the service provider that requires the user?

Please or to participate in this conversation.