core-bundle/src/EventListener/UserAwareTrait.php
protected function hasUser(): bool
    {
        $user = $this->tokenStorage->getToken();

        if (null === $user) {
            return false;
        }

        return !($user instanceof AnonymousToken);
    }
protected function hasUser(): bool
    {
        $user = $this->tokenStorage->getToken();

        if (null === $user) {
            return false;
        }

        return !($user instanceof AnonymousToken);
    }
Checks if there is an authenticated user.