src/EventListener/AuthenticationListener.php line 28

Open in your IDE?
  1. <?php
  2. namespace App\EventListener;
  3. use Lexik\Bundle\JWTAuthenticationBundle\Event\AuthenticationSuccessEvent;
  4. use Lexik\Bundle\JWTAuthenticationBundle\Event\AuthenticationFailureEvent;
  5. use Lexik\Bundle\JWTAuthenticationBundle\Response\JWTAuthenticationFailureResponse;
  6. use Symfony\Component\Serializer\SerializerInterface;
  7. use App\Service\UserService;
  8. class AuthenticationListener
  9. {
  10.     /**
  11.      * @var SerializerInterface
  12.      */
  13.     private $serializer;
  14.     private $UserService;
  15.     public function __construct(SerializerInterface $serializerUserService $UserService)
  16.     {
  17.         $this->serializer $serializer;
  18.         $this->UserService $UserService;
  19.     }
  20.     /**
  21.      * @param AuthenticationSuccessEvent $event
  22.      */
  23.     public function onAuthenticationSuccessResponse(AuthenticationSuccessEvent $event)
  24.     {
  25.         // if(str_contains(get_class($event->getUser()), 'Agency')){
  26.         //     $event->setData([
  27.         //         'id' => $event->getUser()->getId(),
  28.         //         'firstName' => $event->getUser()->getFirstName(),
  29.         //         'lastName' => $event->getUser()->getLastName(),
  30.         //         'email' => $event->getUser()->getEmail(),
  31.         //         'logo' => $event->getUser()->getLogo(),
  32.         //         'role' => $event->getUser()->getRoles()[0],
  33.         //         'token' => $event->getData()['token'],
  34.         //     ]);
  35.         // }
  36.         // if(str_contains(get_class($event->getUser()), 'User')){
  37.             $event->setData([
  38.                 'id' => $event->getUser()->getId(),
  39.                 'firstName' => $event->getUser()->getFirstName(),
  40.                 'lastName' => $event->getUser()->getLastName(),
  41.                 'logo' => $event->getUser()->getLogo(),
  42.                 'email' => $event->getUser()->getEmail(),
  43.                 'role' => $event->getUser()->getRoles()[0],
  44.                 'token' => $event->getData()['token'],
  45.             ]);
  46.         //}
  47.     }
  48. }