Skip to content

Commit a31db71

Browse files
deluxetomcleptric
andauthored
#910 - Don’t try to get session when it’s stateless (#911)
Co-authored-by: Michi Hoffmann <cleptric@users.noreply.github.com>
1 parent 2f19c19 commit a31db71

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/EventListener/LoginListener.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,11 @@ public function __construct(HubInterface $hub, ?TokenStorageInterface $tokenStor
4747
*/
4848
public function handleKernelRequestEvent(RequestEvent $event): void
4949
{
50-
if (null === $this->tokenStorage || !$this->isMainRequest($event)) {
50+
if (
51+
null === $this->tokenStorage
52+
|| !$this->isMainRequest($event)
53+
|| $event->getRequest()->attributes->get('_stateless')
54+
) {
5155
return;
5256
}
5357

tests/EventListener/LoginListenerTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,18 @@ public function __toString(): string
298298
}
299299
}
300300

301+
public function testHandleKernelRequestEventDoesNothingIfRequestIsForStatelessRoute(): void
302+
{
303+
$this->tokenStorage->expects($this->never())
304+
->method('getToken');
305+
306+
$this->listener->handleKernelRequestEvent(new RequestEvent(
307+
$this->createMock(HttpKernelInterface::class),
308+
new Request([], [], ['_stateless' => true]),
309+
HttpKernelInterface::SUB_REQUEST
310+
));
311+
}
312+
301313
public function testHandleKernelRequestEventDoesNothingIfRequestIsNotMain(): void
302314
{
303315
$this->tokenStorage->expects($this->never())

0 commit comments

Comments
 (0)