I m newbies on Symfony (I've been started for a month), I want to do Login/Register System with JWT and I use library LexikJWTAuthenticationBundle. My Problem, I want to customize the login_check response and I made my custom success listeners like here,
and I'm see a error like this when I try to run :
<!-- Argument 1 passed to Symfony\Component\Security\Http\Authentication\CustomAuthenticationSuccessHandler::__construct() must implement interface Symfony\Component\Security\Http\Authentication\AuthenticationSuccessHandlerInterface, instance of App\Listeners\AuthenticationSuccessListener given, called in /home/isha/work/coding/backend/api-colis/api-colis/var/cache/dev/ContainerA3xno95/getSecurity_Authenticator_JsonLogin_LoginService.php on line 48 (500 Internal Server Error) -->
Argument 1 passed to Symfony\Component\Security\Http\Authentication\CustomAuthenticationSuccessHandler::__construct() must implement interface Symfony\Component\Security\Http\Authentication\AuthenticationSuccessHandlerInterface, instance of App\Listeners\AuthenticationSuccessListener given, called in /home/isha/work/coding/backend/api-colis/api-colis/var/cache/dev/ContainerA3xno95/getSecurity_Authenticator_JsonLogin_LoginService.php on line 48
I need help for, the custom success handler, custom response from Lexik JWT and for this problem. Thank You, have a nice day
I write my custom success_handler
<?php
// file : src/Listeners/AuthenticationSuccessListener.php
namespace App\Listeners;
use Lexik\Bundle\JWTAuthenticationBundle\Event\AuthenticationSuccessEvent;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Http\Authentication\AuthenticationSuccessHandlerInterface;
class AuthenticationSuccessListener{
public function onAuthenticationSuccessResponse(AuthenticationSuccessEvent $event){
$event->setData([
'status' => $event->getResponse()->getStatusCode(),
'data' => $event->getData(),
]);
}
}
and register on a service.yaml
like this :
# Custom listener success login
app.listener.authentication_success_response:
class: App\Listeners\AuthenticationSuccessListener
tags:
- { name: kernel.event_listener, event: lexik_jwt_authentication.handler.authentication_success, method: onAuthenticationSuccessResponse }
and on a security.yaml
:
json_login:
check_path: /api/v1/login_check
username_path: username
password_path: password
# success_handler: lexik_jwt_authentication.handler.authentication_success
success_handler: app.listener.authentication_success_response
Thanks for everyone, I found a solution. I rewrite my SuccessHandler like this :
and got response like this :