AuthenticationSuccessListener.php (712B)
1 <?php 2 3 namespace App\EventListener; 4 5 // src/App/EventListener/AuthenticationSuccessListener.php 6 use Lexik\Bundle\JWTAuthenticationBundle\Event\AuthenticationSuccessEvent; 7 8 class AuthenticationSuccessListener 9 { 10 /** 11 * @param AuthenticationSuccessEvent $event 12 */ 13 public function onAuthenticationSuccessResponse(AuthenticationSuccessEvent $event) 14 { 15 $data = $event->getData(); 16 $user = $event->getUser(); 17 $resp = $event->getResponse(); 18 19 // if (!$user instanceof UserInterface) { 20 // return; 21 // } 22 23 $data['data'] = array( 24 'roles' => $user->getRoles(), 25 'foo' => $user 26 ); 27 28 $event->setData($data); 29 } 30 }