<?php
namespace App\EventSubscriber;
use Lexik\Bundle\JWTAuthenticationBundle\Event\JWTCreatedEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Security\Core\User\UserInterface;
/**
* @todo VĂ©rifier si on conserve le subscriber ou le listener
*/
class JwtCreatedSubscriber implements EventSubscriberInterface
{
public static function getSubscribedEvents(): array
{
return [
JWTCreatedEvent::class => 'onJWTCreated',
];
}
public function onJWTCreated(JWTCreatedEvent $event): void
{
$data = $event->getData();
$user = $event->getUser();
if (!$user instanceof UserInterface) {
return;
}
$data['email'] = $user->getEmail();
$data['roles'] = $user->getRoles();
$data['testkey'] = 'testvalue';
$event->setData($data);
file_put_contents('test.txt', 'text');
}
}