<?php
namespace App\EventListener;
use Lexik\Bundle\JWTAuthenticationBundle\Event\JWTExpiredEvent;
use Lexik\Bundle\JWTAuthenticationBundle\Response\JWTAuthenticationFailureResponse;
use Symfony\Component\HttpFoundation\JsonResponse;
class JWTExpiredListener {
/**
* @param JWTExpiredEvent $event
*/
public function onJWTExpiredResponse(JWTExpiredEvent $event)
{
$data = array(
'error' => true,
'status' => 'token_expired',
'message' => array(
'fr' => 'Token expiré',
'en' => 'Expired token'
)
);
$response = new JWTAuthenticationFailureResponse('token_expired', JsonResponse::HTTP_UNAUTHORIZED);
$response->setData($data);
$event->setResponse($response);
}
}