Good morning to all
Please i need help. I am using JWT Authentication and all works well.But my problem is to retreive the current user after the login. I saw in the documentation that i can create a controller to do so, but after doing that i get the error of id parameter not given.
Here is my controller related to the user entity
<?php
// api/src/Controller/GetMeAction.php
namespace AppController;
use AppEntityUser;
use SymfonyComponentSecurityCoreSecurity;
use SymfonyComponentRoutingAnnotationRoute;
class GetMeAction
{
/**
* @param Security
*/
private $_security;
public function __construct(Security $security) {
$this->_security = $security;
}
/**
* @Route(
* name="get_me",
* path="get/me",
* methods={"GET"},
* defaults={
* "_api_resource_class"=User::class,
* "_api_item_operation_name"="get_me"
* }
* )
*/
public function __invoke(Request $request): User
{
return $this->_security->getUser();
}
}
Source: Symfony Questions
Was this helpful?
0 / 0