I have a Service that get\'s the current logged in user, which only works some of the time whilst in the dev environment.
The problem seems to be whenever I change t
I'm not certain, but it looks to me like your class should maintain a pointer to the tokenStorage class, not the token itself (as this may change). Your service would then look like this:
class MyService
{
private $em;
private $tokenStorage;
public function __construct($entityManager, TokenStorageInterface $tokenStorage)
{
$this->em = $entityManager;
$this->tokenStorage = $tokenStorage;
}
public function doSomething()
{
$user_id = $this->tokenStorage->getToken()->getUser()->getID();
return;
}
}