<?php
namespace App\EventSubscriber;
use Lexik\Bundle\JWTAuthenticationBundle\Event\JWTCreatedEvent;
use Symfony\Component\Security\Core\Security;
class JWTCreatedListener
{
private $user;
public function __construct(Security $security)
{
$this->user= $security->getUser();
}
public function onJWTCreated(JWTCreatedEvent $event)
{
$payload = $event->getData();
$payload['firstname'] = $this->user->getFirstname();
$payload['lastname'] = $this->user->getLastname();
$event->setData($payload);
}
}