<?php
namespace App\EventListener;
use App\Services\TokenManager;
use Symfony\Component\HttpFoundation\RequestStack;
use Lexik\Bundle\JWTAuthenticationBundle\Event\JWTInvalidEvent;
use Lexik\Bundle\JWTAuthenticationBundle\Response\JWTAuthenticationFailureResponse;
use Symfony\Component\HttpFoundation\JsonResponse;
class JWTInvalidListener
{
protected $tokenManager;
function __construct(
RequestStack $request,
TokenManager $tokenManager
)
{
$this->request = $request;
$this->tokenManager = $tokenManager;
}
/**
* @param JWTInvalidEvent $event
*
* @return void
*/
public function onJWTInvalid(JWTInvalidEvent $event)
{
if($this->tokenManager->removeCustomerDeviceInvalid()){
$response = new JsonResponse([
"code"=> 403,
"message"=> "The token was banned"
], 401);
$event->setResponse($response);
}
}
}