<?php
namespace App\EventSubscriber;
use Lexik\Bundle\JWTAuthenticationBundle\Event\AuthenticationSuccessEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class AuthenticationSuccessListener implements EventSubscriberInterface
{
public function onAuthenticationSuccess(AuthenticationSuccessEvent $event)
{
$data = $event->getData();
$user = $event->getUser();
// Ajouter la valeur de l'utilisateur dans le token JWT
$data['emailUser'] = $user->getEmailUser();
$event->setData($data);
}
public static function getSubscribedEvents()
{
return [
'lexik_jwt_authentication.on_authentication_success' => 'onAuthenticationSuccess',
];
}
}