src/EventListener/JWTCreatedListener.php line 29

Open in your IDE?
  1. <?php
  2. namespace App\EventListener;
  3. use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
  4. use Lexik\Bundle\JWTAuthenticationBundle\Event\JWTCreatedEvent;
  5. use Symfony\Component\HttpFoundation\RequestStack;
  6. class JWTCreatedListener {
  7.     /**
  8.      * @var RequestStack
  9.      */
  10.     private $requestStack;
  11.     /**
  12.      * @param RequestStack $requestStack
  13.      */
  14.     public function __construct(RequestStack $requestStack)
  15.     {
  16.         $this->requestStack $requestStack;
  17.     }
  18.     /**
  19.      * @param JWTCreatedEvent $event
  20.      *
  21.      * @return void
  22.      */
  23.     public function onJWTCreatedResponse(JWTCreatedEvent $event)
  24.     {        
  25.         $user $event->getUser();
  26.         $payload $event->getData();
  27.         $payload['lastname'] = $user->getLastname();
  28.         $payload['firstname'] = $user->getFirstname();
  29.         $event->setData($payload);
  30.         
  31.         $header $event->getHeader();
  32.         $event->setHeader($header);
  33.     }
  34. }