diff --git a/src/EventListener/LoginListener.php b/src/EventListener/LoginListener.php index 2a766cc7..ef663efb 100644 --- a/src/EventListener/LoginListener.php +++ b/src/EventListener/LoginListener.php @@ -47,7 +47,11 @@ public function __construct(HubInterface $hub, ?TokenStorageInterface $tokenStor */ public function handleKernelRequestEvent(RequestEvent $event): void { - if (null === $this->tokenStorage || !$this->isMainRequest($event)) { + if ( + null === $this->tokenStorage + || !$this->isMainRequest($event) + || $event->getRequest()->attributes->get('_stateless') + ) { return; } diff --git a/tests/EventListener/LoginListenerTest.php b/tests/EventListener/LoginListenerTest.php index 34c37e3d..da037bef 100644 --- a/tests/EventListener/LoginListenerTest.php +++ b/tests/EventListener/LoginListenerTest.php @@ -298,6 +298,18 @@ public function __toString(): string } } + public function testHandleKernelRequestEventDoesNothingIfRequestIsForStatelessRoute(): void + { + $this->tokenStorage->expects($this->never()) + ->method('getToken'); + + $this->listener->handleKernelRequestEvent(new RequestEvent( + $this->createMock(HttpKernelInterface::class), + new Request([], [], ['_stateless' => true]), + HttpKernelInterface::SUB_REQUEST + )); + } + public function testHandleKernelRequestEventDoesNothingIfRequestIsNotMain(): void { $this->tokenStorage->expects($this->never())