diff --git a/Context/UserContextFactory.php b/Context/UserContextFactory.php index 5a9d9ee..367d56d 100644 --- a/Context/UserContextFactory.php +++ b/Context/UserContextFactory.php @@ -15,6 +15,7 @@ use Qandidate\Toggle\Context; use Qandidate\Toggle\ContextFactory; +use Symfony\Component\Security\Core\Authentication\Token\NullToken; use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; class UserContextFactory extends ContextFactory @@ -35,8 +36,8 @@ public function createContext(): Context $token = $this->tokenStorage->getToken(); - if (null !== $token) { - $context->set('username', $token->getUsername()); + if (null !== $token && !$token instanceof NullToken) { + $context->set('username', method_exists($token, 'getUserIdentifier') ? $token->getUserIdentifier() : $token->getUsername()); } return $context;