From 3bd97bb65ff615a523d66c98b1d984dd41c739ba Mon Sep 17 00:00:00 2001 From: Daniel Date: Tue, 23 Jan 2024 18:07:28 +0100 Subject: [PATCH] IRI User login --- config/services.yaml | 2 +- .../AuthenticationSuccessListener.php | 15 +++++++++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/config/services.yaml b/config/services.yaml index fdfd18b..aa7d877 100644 --- a/config/services.yaml +++ b/config/services.yaml @@ -27,4 +27,4 @@ services: class: App\EventListener\AuthenticationSuccessListener tags: - { name: kernel.event_listener, event: lexik_jwt_authentication.on_authentication_success, method: onAuthenticationSuccessResponse } - arguments: ['@api_platform.iri_converter'] \ No newline at end of file + arguments: ['@symfonycasts.micro_mapper', '@api_platform.iri_converter'] \ No newline at end of file diff --git a/src/EventListener/AuthenticationSuccessListener.php b/src/EventListener/AuthenticationSuccessListener.php index 1be827b..1575b36 100644 --- a/src/EventListener/AuthenticationSuccessListener.php +++ b/src/EventListener/AuthenticationSuccessListener.php @@ -9,12 +9,17 @@ namespace App\EventListener; use ApiPlatform\Api\IriConverterInterface; +use App\ApiResource\UserApi; use App\Entity\User; use Lexik\Bundle\JWTAuthenticationBundle\Event\AuthenticationSuccessEvent; +use Symfonycasts\MicroMapper\MicroMapperInterface; class AuthenticationSuccessListener { - public function __construct(private IriConverterInterface $iriConverter) + public function __construct( + private MicroMapperInterface $microMapper, + private IriConverterInterface $iriConverter + ) { } @@ -32,13 +37,15 @@ class AuthenticationSuccessListener return; } - $data['id'] = $user->getId(); - //$data['id'] = $this->iriConverter->getIriFromResource($user); + $userApi = $this->microMapper->map($user, UserApi::class, [ + MicroMapperInterface::MAX_DEPTH => 3, + ]); + + $data['id'] = $this->iriConverter->getIriFromResource($userApi); $data['email'] = $user->getEmail(); $data['firstName'] = $user->getFirstName(); $data['lastName'] = $user->getLastName(); $data['roles'] = $user->getRoles(); - $event->setData($data); } } \ No newline at end of file