© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•3y ago•
2 replies
DGINX

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()
auth()->user()
function because it's every time
null
null
, i have to use instead
Filament::auth()->user()
Filament::auth()->user()
. I created a custom
admin
admin
guard with the Model
SystemUser
SystemUser
. The login works fine with them.

My Question is: Is it really true, that i cannot use
auth()->user()
auth()->user()
, when i use a custom guard? Because i installed an Plugin
https://filamentphp.com/plugins/shuvroroy-spatie-laravel-backup
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
https://github.com/shuvroroy/filament-spatie-laravel-backup/blob/main/src/Components/BackupDestinationListRecords.php
on Line
78
78
he used
auth()->user()->can('delete-backup')
auth()->user()->can('delete-backup')
. But this throws an error, because
auth()->user()
auth()->user()
is still
null
null
.

If i use no custom guards, just the regular
User
User
Model, everything works fine. The Plugin works without problems and when i call
auth()->user()
auth()->user()
it's no more
null
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,
];
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,
];
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel • Build and ship admin panels & apps fast with Livewire
20,307Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

auth()->user() is null after login
FilamentFFilament / ❓┊help
2y ago
auth()->user( ) returns null in shouldRegisterNavigation()
FilamentFFilament / ❓┊help
3y ago
auth()->user() returns null on dashboard canAccess method
FilamentFFilament / ❓┊help
11mo ago
passing auth user to script data return null
FilamentFFilament / ❓┊help
3y ago