Hello,
it seems handling of data returned from __invoke() method of class that implements MessageHandlerInterface is not correct.
Sending request to /users/password-reset-confirmation.
Expected behavior:
Api platform should return a response object that was returned from __invoke().
In this particular case I'm trying to return JWTAuthenticationSuccessResponse which extends JsonResponse.
Current behavior:
Uncaught PHP Exception Symfony\Component\HttpKernel\Exception\ControllerDoesNotReturnResponseException: "The controller must return a "Symfony\Component\HttpFoundation\Response" object but it returned an object of type App\Dto\User\UserPasswordResetConfirmation." at /srv/vendor/api-platform/core/src/Action/PlaceholderAction.php line 32
DTO class UserPasswordResetConfirmation.php:
namespaceApp\Dto\User;
useApp\ValidatorasAppAssert;
useSymfony\Component\Validator\ConstraintsasAssert;
finalclass UserPasswordResetConfirmation
{
/** * @var string * @Assert\NotBlank() * @AppAssert\IsHash() */public$passwordResetToken;
/** * @var string * @Assert\NotBlank() * @AppAssert\PlainPassword() */public$plainPassword;
}API Resource config user_password_reset_confirmation.yaml:
App\Dto\User\UserPasswordResetConfirmation:
attributes:
messenger: trueoutput: falseitemOperations: {}collectionOperations:
post:
access_control: 'is_anonymous()'path: '/users/password-reset-confirmation'status: 200swagger_context:
tags: ['User']summary: 'Confirms and sets new password'responses:
200:
description: 'Successfully set new password, returning a new JWT token'schema:
type: 'object'properties:
token:
type: 'string'description: 'JWT authentication token'400:
description: 'Invalid input'404:
description: 'Resource not found'Message handler class UserPasswordResetConfirmationHandler.php:
namespaceApp\Handler;
useApp\Dto\User\UserPasswordResetConfirmation;
useApp\Event\UserEvent;
useApp\Service\User\UserService;
useApp\Traits\EventDispatcherable;
useLexik\Bundle\JWTAuthenticationBundle\Security\Http\Authentication\AuthenticationSuccessHandler;
useSymfony\Component\Messenger\Handler\MessageHandlerInterface;
class UserPasswordResetConfirmationHandler implements MessageHandlerInterface
{
use EventDispatcherable;
/** * @var UserService */private$userService;
/** * @var AuthenticationSuccessHandler */private$authenticationHandler;
publicfunction__construct(UserService$userService, AuthenticationSuccessHandler$authenticationHandler)
{
$this->userService = $userService;
$this->authenticationHandler = $authenticationHandler;
}
publicfunction__invoke(UserPasswordResetConfirmation$dto)
{
$user = $this->userService->confirmPasswordReset($dto);
$this->dispatch(UserEvent::PASSWORD_RESET_CONFIRMED, newUserEvent($user));
// creating a new JWT token$response = $this->authenticationHandler->handleAuthenticationSuccess($user);
return$response;
}
}Debugging showed that event is populated with response object vendor/api-platform/core/src/EventListener/WriteListener.php at lines 60-66:
$persistResult = $this->dataPersister->persist($controllerResult);
//$event->setControllerResult($persistResult ?? $controllerResult);
but later on somewhere controller result is overwritten with DTO object UserPasswordResetConfirmation, than becomes a cause of an exception.
Hello,
it seems handling of data returned from
__invoke()method of class that implementsMessageHandlerInterfaceis not correct.Sending request to
/users/password-reset-confirmation.Expected behavior:
Api platform should return a response object that was returned from
__invoke().In this particular case I'm trying to return
JWTAuthenticationSuccessResponsewhich extendsJsonResponse.Current behavior:
DTO class
UserPasswordResetConfirmation.php:API Resource config
user_password_reset_confirmation.yaml:Message handler class
UserPasswordResetConfirmationHandler.php:Debugging showed that event is populated with response object
vendor/api-platform/core/src/EventListener/WriteListener.phpat lines 60-66:but later on somewhere controller result is overwritten with DTO object
UserPasswordResetConfirmation, than becomes a cause of an exception.