<?php
declare(strict_types=1);

namespace App\EventListener\JWT;

use Lexik\Bundle\JWTAuthenticationBundle\Event\AuthenticationSuccessEvent;
use Symfony\Component\Security\Core\User\UserInterface;

/**
 * Class AuthenticationSuccessListener : Listener appelé lors d'une authentification réussie ou ratée
 * @package App\EventListener\JWT
 */
class AuthenticationSuccessListener {
    /**
     * Appelé lors d'une authentification réussie
     * @param AuthenticationSuccessEvent $event
     */
    public function onAuthenticationSuccessResponse(AuthenticationSuccessEvent $event): void
    {
        $data = $event->getData();
        $user = $event->getUser();

        if (!$user instanceof UserInterface) {
            return;
        }

        $event->setData($data);
    }
}