src/EventSubscriber/JWTCreatedListener.php line 20

Open in your IDE?
  1. <?php
  2. namespace App\EventSubscriber;
  3. use Lexik\Bundle\JWTAuthenticationBundle\Event\JWTCreatedEvent;
  4. use Symfony\Component\Security\Core\Security;
  5. class JWTCreatedListener
  6. {
  7.     private $user;
  8.     public function __construct(Security $security)
  9.     {
  10.            $this->user$security->getUser();
  11.     }
  12.     public function onJWTCreated(JWTCreatedEvent $event)
  13.     {
  14.         $payload  =     $event->getData();
  15.         $payload['firstname'] = $this->user->getFirstname();
  16.         $payload['lastname'] = $this->user->getLastname();
  17.         $event->setData($payload);
  18.     }
  19. }