@ahoi Why are you trying to use that middleware for API routes? API routes are stateless, but that middleware requires the session, which is stateful: https://github.com/laravel/framework/blob/213a370b703592587bafcd52d38a0ad772ff7442/src/Illuminate/Auth/Middleware/RequirePassword.php#L96
Jul 11, 2024
7
Level 5
HTTP 500 in PEST tests when using password.confirm middleware
Hi there,
I am using Laravel 11 with Sanctum and Fortify. Now I want to test an api endpoint, which got an additional middleware: password.confirm.
The tests throw HTTP 500.:
RuntimeException: Session store not set on request. in /Users/ahoi/Entwicklung/Laravel/carter/vendor/laravel/framework/src/Illuminate/Http/Request.php:564
Outside of the test scope this does not happen.
This is my test:
it('will only accept valid payloads', function (User $user, array $payload, int $httpResponseCode) {
//Arrange
login($user);
//Act
$request = patchJson(
uri : route('user.name.update', $user),
data: $payload
);
//Assert
expect($request)
->toHaveStatus($httpResponseCode);
})->with('requests');
The login function is defined this way:
function login(User $user = null): void
{
actingAs($user ?? User::factory()->createOne());
}
If I remove the middleware, everything works as expected.
Any idea why this is happening?
Please or to participate in this conversation.