code: public function getFrontendUsername(): ?string
      {
          $token = $this->getToken(FrontendUser::SECURITY_SESSION_KEY);
  
          if (null === $token || !$token->getUser() instanceof FrontendUser) {
              return null;
          }
  
          return $token->getUser()->getUsername();
      }
docs: Gets the front end username from the session.