<?php
namespace App\EventListener;
use Lexik\Bundle\JWTAuthenticationBundle\Event\JWTNotFoundEvent;
use Lexik\Bundle\JWTAuthenticationBundle\Response\JWTAuthenticationFailureResponse;
use Symfony\Contracts\Translation\TranslatorInterface;
class JWTNotFoundListener
{
private TranslatorInterface $translator;
public function __construct(TranslatorInterface $translator)
{
$this->translator = $translator;
}
public function onJWTNotFound(JWTNotFoundEvent $event): void
{
/** @var JWTAuthenticationFailureResponse $response */
$response = $event->getResponse();
$response->setMessage($this->translator->trans('Missing token.', [], 'security'));
}
}