mostafa-amine's avatar

Laravel Tests - Auth::user() returns null when consumed by after registration Middelware

I'm writing tests for an application, specificly for user registration.

The correct behaviour should be when the user registred, A middleware should check if the user pack is still valid wich requires a user object.

However, the test method assertAuthenticated passes but when i fetch for a user using Auth::user() in the middelware code it returns null.

Test Code

$this->assertAuthenticated();
$response->assertRedirect(route('packs.view'));

Middelware code

if (Auth::check() && Auth::user()?->role === RoleEnum::Instructor->value)
0 likes
0 replies

Please or to participate in this conversation.