<?php
namespace App\EventListener;
use Lexik\Bundle\JWTAuthenticationBundle\Event\AuthenticationSuccessEvent;
use Lexik\Bundle\JWTAuthenticationBundle\Event\AuthenticationFailureEvent;
use Lexik\Bundle\JWTAuthenticationBundle\Response\JWTAuthenticationFailureResponse;
use Symfony\Component\Serializer\SerializerInterface;
use App\Service\UserService;
class AuthenticationListener
{
/**
* @var SerializerInterface
*/
private $serializer;
private $UserService;
public function __construct(SerializerInterface $serializer, UserService $UserService)
{
$this->serializer = $serializer;
$this->UserService = $UserService;
}
/**
* @param AuthenticationSuccessEvent $event
*/
public function onAuthenticationSuccessResponse(AuthenticationSuccessEvent $event)
{
// if(str_contains(get_class($event->getUser()), 'Agency')){
// $event->setData([
// 'id' => $event->getUser()->getId(),
// 'firstName' => $event->getUser()->getFirstName(),
// 'lastName' => $event->getUser()->getLastName(),
// 'email' => $event->getUser()->getEmail(),
// 'logo' => $event->getUser()->getLogo(),
// 'role' => $event->getUser()->getRoles()[0],
// 'token' => $event->getData()['token'],
// ]);
// }
// if(str_contains(get_class($event->getUser()), 'User')){
$event->setData([
'id' => $event->getUser()->getId(),
'firstName' => $event->getUser()->getFirstName(),
'lastName' => $event->getUser()->getLastName(),
'logo' => $event->getUser()->getLogo(),
'email' => $event->getUser()->getEmail(),
'role' => $event->getUser()->getRoles()[0],
'token' => $event->getData()['token'],
]);
//}
}
}