<?php
namespace App\EventListener;
use Lexik\Bundle\JWTAuthenticationBundle\Event\JWTInvalidEvent;
use Lexik\Bundle\JWTAuthenticationBundle\Response\JWTAuthenticationFailureResponse;
use Symfony\Component\HttpFoundation\JsonResponse;
class JWTInvalidListener
{
/**
* @param JWTInvalidEvent $event
*/
public function onJWTInvalid(JWTInvalidEvent $event)
{
// Custom status code & error message
$code = JsonResponse::HTTP_FORBIDDEN;
$message = "Votre jeton est invalide, merci de vous reconnecter pour en obtenir un nouveau";
$response = new JWTAuthenticationFailureResponse($message, $code);
$event->setResponse($response);
}
}