<?php
namespace App\EventListener;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
use Lexik\Bundle\JWTAuthenticationBundle\Event\JWTCreatedEvent;
use Symfony\Component\HttpFoundation\RequestStack;
class JWTCreatedListener {
/**
* @var RequestStack
*/
private $requestStack;
/**
* @param RequestStack $requestStack
*/
public function __construct(RequestStack $requestStack)
{
$this->requestStack = $requestStack;
}
/**
* @param JWTCreatedEvent $event
*
* @return void
*/
public function onJWTCreatedResponse(JWTCreatedEvent $event)
{
$user = $event->getUser();
$payload = $event->getData();
$payload['lastname'] = $user->getLastname();
$payload['firstname'] = $user->getFirstname();
$event->setData($payload);
$header = $event->getHeader();
$event->setHeader($header);
}
}