get_class(): Argument #1 ($object) must be of type object, null given Filament::auth()
I have a common resource for multiple users (User model, Artist Model, Affiliate Model) etc.
in the list page, in table query I have like this.. to only load logged in user specific records
here we basicaly call where user_type = current auth user class
this works fine ..
but in test , when I do
I also add beforeEach for my pest test
I try to do this too chain with actingAs()->startSession() but still same error
I get this error : get_class(): Argument #1 ($object) must be of type object, null given
why Filament::auth()->user() is null while user actingAs and how to fix this..
9 Replies
Your post would be more readable if you used code formatting. #✅┊rules
Done
You are using the default auth for Filament?
I have 5 different panels with 5 different user models and guards.
for each panel I have applied the specific guard with the authGuard function
how do I test this panels seperately because filament::auth() function does not work in test.
Then you should use the auth guard as your second argument:
$this->actingAs(User::factory()->create(), 'affiliate');
I already pass the guard when actingAs
like this..
etc.
but still not working. I pass guard with individual user models while actingAs but Filament::auth::user() or any method chained to it fails for null
the test passed when I do like this.
So, when I do login with filament Filament::auth()->login($user);
then the it gets Filament::auth()::user(),
is actingAs() not enough for authenticate user
Hm, interesting. I am not sure what might be the issue here.
so, any solution..
I could be wrong, but how can more than one user be logged in for the test? Wouldn’t each actingAs() override the previous one?