src/Listener/AuthenticationSuccessListener.php line 31

Open in your IDE?
  1. <?php
  2. namespace App\Listener;
  3. use Lexik\Bundle\JWTAuthenticationBundle\Event\AuthenticationSuccessEvent;
  4. use Symfony\Component\Serializer\SerializerInterface;
  5. use Symfony\Component\Serializer\Encoder\JsonEncoder;
  6. use Symfony\Component\Security\Core\User\UserInterface;
  7. class AuthenticationSuccessListener
  8. {
  9.     /**
  10.      * @var SerializerInterface
  11.      */
  12.     protected $serializer;
  13.     /**
  14.      * LicenciaValidaValidator constructor.
  15.      * @param SerializerInterface $serializer
  16.      */
  17.     public function __construct(SerializerInterface $serializer)
  18.     {
  19.         $this->serializer $serializer;
  20.     }
  21.     /**
  22.      * @param AuthenticationSuccessEvent $event
  23.      */
  24.     public function onAuthenticationSuccessResponse(AuthenticationSuccessEvent $event)
  25.     {
  26.         $data $event->getData();
  27.         $user $event->getUser();
  28.         if (!$user instanceof UserInterface) {
  29.             return;
  30.         }
  31.         $data['user'] = $this->serializer->serialize($userJsonEncoder::FORMAT);
  32.         //
  33.         $event->setData($data);
  34.     }
  35. }