Helle there !
I'm currently working on a auth with JWT. I'm with Symfony 5.3 I have an error when I want to test my login :
<!-- Cannot autowire argument $user of "App\Controller\AuthController::getTokenUser()": it references interface "Symfony\Component\Security\Core\User\UserInterface" but no such service exists. Did you create a class that implements this interface? (500 Internal Server Error) -->
I have installed security bundle and my user entity :
class User implements UserInterface, PasswordAuthenticatedUserInterface
Can someone helps me ?
Thanks
CodePudding user response:
Maybe have you written the line:
class User implements UserInterface, PasswordAuthenticatedUserInterface
without previously creating the use
statement?
use Symfony\Component\Security\Core\User\UserInterface;
It is a typical overlook when you are used to your IDE doing it for you, and at a particular moment it doesn't happen.
If this is the case, this also applies to PasswordAuthenticatedUserInterface
CodePudding user response:
The error says there's an issue with your AuthController::getTokenUser()
method, not with your User
class. Could you post that method's signature?
My guess based on what you posted is that your method looks something like this:
public function getTokenUser(UserInterface $user)...
If you need the current User
in that controller method, you should inject Symfony\Component\Security\Core\Security
and then call $security->getUser()
like this:
public function getTokenUser (Security $security)
{
$user = $security->getUser();
}