auth()->user() everytime null

Hello,

i'm new at filament. I'm not sure but i read multiple times that i can't use auth()->user() function because it's every time
null
, i have to use instead Filament::auth()->user() . I created a custom admin guard with the Model SystemUser. The login works fine with them.

My Question is: Is it really true, that i cannot use auth()->user(), when i use a custom guard? Because i installed an Plugin https://filamentphp.com/plugins/shuvroroy-spatie-laravel-backup.

And inside his code https://github.com/shuvroroy/filament-spatie-laravel-backup/blob/main/src/Components/BackupDestinationListRecords.php on Line 78 he used auth()->user()->can('delete-backup'). But this throws an error, because auth()->user() is still
null
.

If i use no custom guards, just the regular
User
Model, everything works fine. The Plugin works without problems and when i call auth()->user() it's no more
null
.

Here my Code.

config/auth.php
return [
    'defaults' => [
        'guard' => 'web',
        'passwords' => 'users',
    ],
    'guards' => [
        'web' => [
            'driver' => 'session',
            'provider' => 'users',
        ],

        'admin' => [
            'driver' => 'session',
            'provider' => 'admin'
        ]
    ],
    'providers' => [
        'users' => [
            'driver' => 'eloquent',
            'model' => App\Models\User::class,
        ],

        'admin' => [
            'driver' => 'eloquent',
            'model' => App\Models\SystemUser::class,
        ],
    ],
    'passwords' => [
        'users' => [
            'provider' => 'users',
            'table' => 'password_reset_tokens',
            'expire' => 60,
            'throttle' => 60,
        ],
    ],
    'password_timeout' => 10800,
];
Was this page helpful?