Hi,
i麓m trying to add a custom public data to the JWT response and when i follow the instructions for my symfony instalation i麓m getting the following message:
(2/2)聽FileLoaderLoadExceptionThe autoloader expected class "App\EventListener\AuthenticationEventListener" to be defined in file "/Users/fjugaldev/Sites/sftest/civination-backend/vendor/composer/../../src/EventListener/AuthenticationEventListener.php". The file was found but the class was not in it, the class name or namespace probably has a typo in /Users/fjugaldev/Sites/sftest/civination-backend/config/services.yaml (which is loaded in resource "/Users/fjugaldev/Sites/sftest/civination-backend/config/services.yaml").
My services.yml looks like:
acme_api.event.authentication_success_listener:
class: AppBundle\EventListener\AuthenticationSuccessListener
tags:
- { name: kernel.event_listener, event: lexik_jwt_authentication.on_authentication_success, method: onAuthenticationSuccessResponse }
And the class for this service:
use Lexik\Bundle\JWTAuthenticationBundle\Event\AuthenticationSuccessEvent;
/**
* @param AuthenticationSuccessEvent $event
*/
public function onAuthenticationSuccessResponse(AuthenticationSuccessEvent $event)
{
$data = $event->getData();
$user = $event->getUser();
if (!$user instanceof UserInterface) {
return;
}
$data['data'] = array(
'roles' => $user->getRoles(),
);
$event->setData($data);
}
I'm doing everything just like the documentation says.
The next thing i tried is to define the service like this:
App\EventListener\AuthenticationSuccessListener:
tags:
- { name: kernel.event_listener, event: lexik_jwt_authentication.on_authentication_success, method: onAuthenticationSuccessResponse }
But still throwing the same error. I麓m using Symfony 4.
Anybody has any idea?
Thanks
Hi,
Error says AuthenticationEventListener.php but service definition says AuthenticationSuccessListener, classname-filename mismatch.
my mistake.. OMG!.. i was obfuscated xD
Thanks @chalasr
Most helpful comment
Hi,
Error says
AuthenticationEventListener.phpbut service definition saysAuthenticationSuccessListener, classname-filename mismatch.