src/EventListener/JWTInvalidListener.php line 29

Open in your IDE?
  1. <?php
  2. namespace App\EventListener;
  3. use App\Services\TokenManager;
  4. use Symfony\Component\HttpFoundation\RequestStack;
  5. use Lexik\Bundle\JWTAuthenticationBundle\Event\JWTInvalidEvent;
  6. use Lexik\Bundle\JWTAuthenticationBundle\Response\JWTAuthenticationFailureResponse;
  7. use Symfony\Component\HttpFoundation\JsonResponse;
  8. class JWTInvalidListener
  9. {
  10.     protected $tokenManager;
  11.     function __construct(
  12.         RequestStack  $request,
  13.         TokenManager $tokenManager
  14.     )
  15.     {
  16.         $this->request $request;
  17.         $this->tokenManager $tokenManager;
  18.     }
  19.     /**
  20.      * @param JWTInvalidEvent $event
  21.      *
  22.      * @return void
  23.      */
  24.     public function onJWTInvalid(JWTInvalidEvent $event)
  25.     {
  26.         if($this->tokenManager->removeCustomerDeviceInvalid()){
  27.             $response = new JsonResponse([
  28.                 "code"=> 403,
  29.                 "message"=> "The token was banned"
  30.             ], 401);
  31.             $event->setResponse($response);
  32.         }
  33.     }
  34. }