Open aynaitlamine opened 1 month ago
This is also causing me problems - when the authentication dies for any reason, there are no errors logged or sent to the user, which was not the behavior with previous versions.
I did find that you can listen to the LoginFailureEvent to implement what this bundle used to do:
<?php
namespace App\EventListener;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\EventDispatcher\Attribute\AsEventListener;
use Symfony\Component\Security\Http\Event\LoginFailureEvent;
use Twig\Environment;
final class LoginFailureListener
{
private Environment $twig;
public function __construct(Environment $twig)
{
$this->twig = $twig;
}
#[AsEventListener(event: LoginFailureEvent::class)]
public function onLoginFailureEvent(LoginFailureEvent $event): void
{
$exception = $event->getException();
$message = sprintf(
'An Authentication Error: %s with code: %s',
$exception->getMessage(),
$exception->getCode()
);
// Customize your response object to display the exception details
$response = new Response(
$this->twig->render('@HWIOAuth/Connect/login.html.twig', ['error' => $message])
);
// sends the modified response object to the event
$event->setResponse($response);
}
}
Actual Behavior
What is the actual behavior? Upon encountering an issue, the system currently redirects users to '/' without displaying any error message.
Expected Behavior
What is the behavior you expect? The expected behavior is to display an error message in JSON format when using Lexik. Specifically, while the success_handler (lexik_jwt_authentication.handler.authentication_success) functions correctly, the failure_handler (lexik_jwt_authentication.handler.authentication_failure) fails to override the default behavior.