-
-
Notifications
You must be signed in to change notification settings - Fork 617
Open
Description
AuthenticationSuccessEvent not triggered on login
Hello and thanks for this bundle,
I am using Symfony 7 with LexikJWTAuthenticationBundle. I configured a subscriber for AuthenticationSuccessEvent and AuthenticationFailureEvent, but when I attempt to login via my /api/login endpoint, the subscriber is never called.
Setup
Symfony version: 7
Firewall configuration:
firewalls:
api:
pattern: ^/api
stateless: true
json_login:
check_path: /api/login
username_path: email
password_path: password
success_handler: lexik_jwt_authentication.handler.authentication_success
failure_handler: lexik_jwt_authentication.handler.authentication_failureSubscriber implementation:
<?php
namespace App\EventSubscriber;
use Lexik\Bundle\JWTAuthenticationBundle\Event\AuthenticationSuccessEvent;
use Lexik\Bundle\JWTAuthenticationBundle\Event\AuthenticationFailureEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class TestLexikSubscriber implements EventSubscriberInterface
{
public static function getSubscribedEvents(): array
{
return [
AuthenticationSuccessEvent::class => 'onAuthenticationSuccessEvent',
AuthenticationFailureEvent::class => 'onAuthenticationFailureEvent',
];
}
public function onAuthenticationSuccessEvent(AuthenticationSuccessEvent $event): void
{
// Debug to check if the event is triggered
dd($event, 'success');
}
public function onAuthenticationFailureEvent(AuthenticationFailureEvent $event): void
{
// Debug to check if the event is triggered
dd($event, 'fail');
}
}Routes configuration:
controllers:
resource:
path: ../src/Controller/
namespace: App\Controller
type: attribute
api_login_check:
path: /api/login
api_refresh_token:
path: /api/token/refresh
api_token_invalidate:
path: /api/token/invalidateProblem
Even though I POST credentials to /api/login, neither of the subscriber methods is called.
The JWT is generated correctly if I use the default success handler, but my subscriber never receives the event.
Autoconfiguration is enabled, and the subscriber is correctly loaded.
Questions
- Should
AuthenticationSuccessEventbe triggered automatically when usingjson_loginin Symfony 7? - Are there any changes in Symfony 7 or the bundle that would prevent the event from being dispatched?
- Is there a recommended way to ensure my subscriber is triggered on successful login?
thanks
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels