code: public function hasBackendUser(): bool
      {
          $token = $this->getToken(BackendUser::SECURITY_SESSION_KEY);
  
          return null !== $token && $token->getUser() instanceof BackendUser;
      }
docs: Checks if a back end user is authenticated.