src/EventListener/AuthenticationSuccessListener.php line 12

Open in your IDE?
  1. <?php
  2. namespace App\EventListener;
  3. use Lexik\Bundle\JWTAuthenticationBundle\Event\AuthenticationSuccessEvent;
  4. use Symfony\Component\Security\Core\User\UserInterface;
  5. class AuthenticationSuccessListener
  6. {
  7.   /**
  8.    * @param AuthenticationSuccessEvent $event
  9.    */
  10.   public function onAuthenticationSuccessResponse(AuthenticationSuccessEvent $event)
  11.   {
  12.     $data $event->getData();
  13.     $user $event->getUser();
  14.     if (!$user instanceof UserInterface) {
  15.       return;
  16.     }
  17.     $data['name'] = $user->getName();
  18.     $data['id'] = $user->getId();
  19.     $event->setData($data);
  20.   }
  21. }