Neos\Neos\Domain\Service\UserService::getCurrentUser PHP Method

getCurrentUser() public method

Returns the currently logged in user, if any
public getCurrentUser ( ) : User
return Neos\Neos\Domain\Model\User The currently logged in user, or null
    public function getCurrentUser()
    {
        if ($this->securityContext->canBeInitialized() === true) {
            $account = $this->securityContext->getAccount();
            if ($account !== null) {
                return $this->getUser($account->getAccountIdentifier());
            }
        }
        return null;
    }

Usage Example

 /**
  * Returns the name of the currently logged in user's personal workspace (even if that might not exist at that time).
  * If no user is logged in this method returns null.
  *
  * @return string
  * @api
  */
 public function getPersonalWorkspaceName()
 {
     $currentUser = $this->userDomainService->getCurrentUser();
     if (!$currentUser instanceof User) {
         return null;
     }
     $username = $this->userDomainService->getUsername($currentUser);
     return $username === null ? null : UserUtility::getPersonalWorkspaceNameForUsername($username);
 }
All Usage Examples Of Neos\Neos\Domain\Service\UserService::getCurrentUser