Today we talk about how in Magento 2 get current admin user detail?. in this tutorial we will cover how to get current admin username and current admin email and other information included as well. So let’s start with our code example.
protected $authSession;
public function __construct(
\Magento\Backend\Model\Auth\Session $authSession,
) {
$this->authSession = $authSession;
}
public function getCurrentUser()
{
return $this->authSession->getUser();
}
public function __construct(
\Magento\Backend\Model\Auth\Session $authSession,
) {
$this->authSession = $authSession;
}
public function getCurrentUser()
{
return $this->authSession->getUser();
}
Now you have access to current admin information. You can get information with the following code.
$this->getCurrentUser->getUsername(); //get admin user name
$this->getCurrentUser->getEmail(); //get current admin email
$this->getCurrentUser->getEmail(); //get current admin email