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

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.     private IriConverterInterface $iriConverter;
  19.     public function __construct(IriConverterInterface $iriConverter)
  20.     {
  21.         $this->iriConverter $iriConverter;
  22.     }
  23.     public function onAuthenticationSuccessResponse(AuthenticationSuccessEvent $event): void
  24.     {
  25.         $data $event->getData();
  26.         $user $event->getUser();
  27.         if (!$user instanceof ShopUserInterface) {
  28.             return;
  29.         }
  30.         /** @var CustomerInterface $customer */
  31.         $customer $user->getCustomer();
  32.         $data['customer'] = $this->iriConverter->getIriFromItem($customer);
  33.         $event->setData($data);
  34.     }
  35. }