src/EventListener/JWTInvalidListener.php line 19

Open in your IDE?
  1. <?php
  2. namespace App\EventListener;
  3. use Lexik\Bundle\JWTAuthenticationBundle\Event\JWTInvalidEvent;
  4. use Lexik\Bundle\JWTAuthenticationBundle\Response\JWTAuthenticationFailureResponse;
  5. use Symfony\Component\HttpFoundation\Response;
  6. use Symfony\Contracts\Translation\TranslatorInterface;
  7. class JWTInvalidListener
  8. {
  9.     private TranslatorInterface $translator;
  10.     public function __construct(TranslatorInterface $translator)
  11.     {
  12.         $this->translator $translator;
  13.     }
  14.     public function onJWTInvalid(JWTInvalidEvent $event): void
  15.     {
  16.         $response = new JWTAuthenticationFailureResponse($this->translator->trans(
  17.             'Your token is invalid, please login again to get a new one.', [], 'security'
  18.         ), Response::HTTP_UNAUTHORIZED);
  19.         $event->setResponse($response);
  20.     }
  21. }