vendor/sylius/sylius/src/Sylius/Bundle/ApiBundle/EventListener/AuthenticationSuccessListener.php line 27

Open in your IDE?
  1. <?php
  2. /*
  3. * This file is part of the Sylius package.
  4. *
  5. * (c) Paweł Jędrzejewski
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. declare(strict_types=1);
  11. namespace Sylius\Bundle\ApiBundle\EventListener;
  12. use ApiPlatform\Core\Api\IriConverterInterface;
  13. use Lexik\Bundle\JWTAuthenticationBundle\Event\AuthenticationSuccessEvent;
  14. use Sylius\Component\Core\Model\CustomerInterface;
  15. use Sylius\Component\Core\Model\ShopUserInterface;
  16. final class AuthenticationSuccessListener
  17. {
  18. public function __construct(private IriConverterInterface $iriConverter)
  19. {
  20. }
  21. public function onAuthenticationSuccessResponse(AuthenticationSuccessEvent $event): void
  22. {
  23. $data = $event->getData();
  24. $user = $event->getUser();
  25. if (!$user instanceof ShopUserInterface) {
  26. return;
  27. }
  28. /** @var CustomerInterface $customer */
  29. $customer = $user->getCustomer();
  30. $data['customer'] = $this->iriConverter->getIriFromItem($customer);
  31. $event->setData($data);
  32. }
  33. }