Update AuthenticationHandler to make session parameter optional and add validation for empty session tokens. Update error message in PresenceRealtimeClientTest for clarity.

This commit is contained in:
ArnabChatterjee20k
2026-05-04 16:22:54 +05:30
parent 0e0e40f991
commit 29092b277b
2 changed files with 6 additions and 2 deletions
@@ -24,7 +24,7 @@ class AuthenticationHandler extends Action
$this
->desc('Authenticate the connection with a session token')
->label(Dispatcher::LABEL_MESSAGE_TYPE, 'authentication')
->param('session', '', new Text(2048), 'Encoded session token')
->param('session', '', new Text(2048), 'Encoded session token', optional: true)
->inject('connection')
->inject('realtime')
->inject('database')
@@ -44,6 +44,10 @@ class AuthenticationHandler extends Action
Registry $register,
Response $response,
): array {
if ($session === '') {
throw new Exception(Exception::REALTIME_MESSAGE_FORMAT_INVALID, 'Payload is not valid.');
}
$store = new Store();
$store->decode($session);
@@ -382,7 +382,7 @@ class PresenceRealtimeClientTest extends Scope
],
]));
$missingStatus = $this->receiveErrorMessage($client);
$this->assertStringContainsString('status must be provided', $missingStatus['data']['message'] ?? '');
$this->assertStringContainsString('status is required', $missingStatus['data']['message'] ?? '');
$this->assertQuietFor(
$client,
fn (array $frame): bool => ($frame['type'] ?? null) === 'event'