refs #450. Added new JWT Decoded data

pull/7/head
Manuel Aranda Rosales 2024-06-13 15:52:46 +02:00
parent 2e12af3c2f
commit 8e03d34720
1 changed files with 29 additions and 0 deletions

View File

@ -0,0 +1,29 @@
<?php
namespace App\Lexik;
use App\Entity\User;
use Lexik\Bundle\JWTAuthenticationBundle\Events;
use Lexik\Bundle\JWTAuthenticationBundle\Event\JWTCreatedEvent;
use Symfony\Component\EventDispatcher\Attribute\AsEventListener;
#[AsEventListener(event: Events::JWT_CREATED, priority: 1)]
class JWTCreatedListener
{
public function __invoke(JWTCreatedEvent $event): void
{
$user = $event->getUser();
if (!$user instanceof User) {
return;
}
$payload = $event->getData();
$payload['id'] = $user->getId();
$payload['username'] = $user->getUsername();
$payload['uuid'] = $user->getUuid();
$payload['roles'] = $user->getRoles();
$event->setData($payload);
}
}