<?php
namespace App\Listener;
use App\Repository\UserRepository;
use Lexik\Bundle\JWTAuthenticationBundle\Event\JWTAuthenticatedEvent;
use Lexik\Bundle\JWTAuthenticationBundle\Event\JWTDecodedEvent;
use Symfony\Component\HttpFoundation\RequestStack;
class JWTDecodedListener {
private $requestStack;
private $userRepository;
/**
* @param RequestStack $requestStack
* @param UserRepository $userRepository
* se ejecuta el segundo
*/
public function __construct(RequestStack $requestStack, UserRepository $userRepository)
{
$this->requestStack = $requestStack;
$this->userRepository = $userRepository;
}
public function onJWTDecoded(JWTDecodedEvent $event)
{
$request = $this->requestStack->getCurrentRequest();
$data = $this->userRepository->findOneByEmail($event->getPayload()['username']);
}
}