{"id":421,"date":"2019-05-16T11:47:34","date_gmt":"2019-05-16T11:47:34","guid":{"rendered":"https:\/\/meetanshi.com\/blog\/2019\/05\/16\/get-current-admin-user-detail-in-magento-2\/"},"modified":"2025-05-22T16:51:48","modified_gmt":"2025-05-22T11:21:48","slug":"get-current-admin-user-detail-in-magento-2","status":"publish","type":"post","link":"https:\/\/meetanshi.com\/blog\/get-current-admin-user-detail-in-magento-2\/","title":{"rendered":"How to Get Current Admin User Detail in Magento 2"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">The admin in Magento 2 knows the admin panel like no one else! There can be as many admin users as required with different level of access and roles. The various roles ensure security to the store.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">There are 3 types of admin roles in Magento 2:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Account owner role<\/li>\n\n\n\n<li>Project-level roles<\/li>\n\n\n\n<li>Environment-level roles<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Each role has its own level of access and tasks. The super admin can assign these roles to the users. After assigning these roles, the admin may need to get the details of current logged in admin user for various purposes such as, sending a message with the details of the admin user, get an Email notification with the admin login details or keep a check on each admins&#8217; activity log! To serve the purpose, the super admin needs to identify the current admin user logged and get the details such as admin username, email address, etc.and other details. Hence, here I&#8217;ll show you how to get current admin user detail in Magento 2.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Methods to Get Current Admin User Detail in Magento 2:<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Implement the below codes, following any of the above methods,<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">1. Using Block:<\/h3>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">namespace Vendor\\Extension\\Block;\nuse Magento\\Backend\\Model\\Auth\\Session\nuse Magento\\Framework\\View\\Element\\Template;\nclass View extends Template\n{\n    protected $authSession;\n    public function __construct(Session $authSession)\n    {\n        $this->authSession = $authSession;\n    }\n    public function getCurrentUser()\n    {\n        return $this->authSession->getUser();\n    }\n}\n\/\/get admin user name $this->getCurrentUser->getUsername();\n\/\/get current admin email $this->getCurrentUser->getEmail();<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">2. Using Object Manager:<\/h3>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">$objectManager = \\Magento\\Framework\\App\\ObjectManager::getInstance();\n$extensionUser = $objectManager->get('Magento\\Backend\\Model\\Auth\\Session')->getUser()->getUsername();<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Follow any of the above methods to <i><strong>get current admin user detail in Magento 2<\/strong><\/i>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Thank you!<i><\/i><\/p>\n","protected":false},"excerpt":{"rendered":"<p>The admin in Magento 2 knows the admin panel like no one else! There can be as many admin users as required with different level&#8230;<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[34],"tags":[],"class_list":["post-421","post","type-post","status-publish","format-standard","hentry","category-magento"],"acf":[],"_links":{"self":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/421","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/comments?post=421"}],"version-history":[{"count":4,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/421\/revisions"}],"predecessor-version":[{"id":15426,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/421\/revisions\/15426"}],"wp:attachment":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/media?parent=421"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/categories?post=421"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/tags?post=421"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}