code: protected function hasUser(): bool
      {
          $user = $this->tokenStorage->getToken();
  
          if (null === $user) {
              return false;
          }
  
          return !($user instanceof AnonymousToken);
      }
docs: Checks if there is an authenticated user.