lib/boab/cms-bundle/src/Api/EventListener/JWTCreatedListener.php line 23

Open in your IDE?
  1. <?php
  2. namespace Boab\CmsBundle\Api\EventListener;
  3. use Lexik\Bundle\JWTAuthenticationBundle\Event\JWTCreatedEvent;
  4. use Symfony\Component\HttpFoundation\RequestStack;
  5. use Symfony\Component\Security\Core\User\UserInterface;
  6. class JWTCreatedListener
  7. {
  8.     private $requestStack;
  9.     public function __construct(RequestStack $request)
  10.     {
  11.         $this->requestStack $request;
  12.     }
  13.     /**
  14.      * @param JWTCreatedEvent $event
  15.      *
  16.      * @return void
  17.      */
  18.     public function onJWTCreated(JWTCreatedEvent $event)
  19.     {
  20.         $request $this->requestStack->getCurrentRequest();
  21.         $payload $event->getData();
  22.         $user $event->getUser();
  23.         if (!$user instanceof UserInterface) {
  24.             return;
  25.         }
  26.         $payload['ip'] = $request->getClientIp();
  27.         $payload['userId'] = $user->getId();
  28.         $event->setData($payload);        
  29.     }    
  30. }