In this blog in explain about how we can get current admin user details from session.

We need to use session class Magento\Backend\Model\Auth\Sessiont to get current loggedin admin data.

Here is simple code is to get admin details. Code is writter with PHP8 and supported to magento 2.4.6 😍 Created one simple class and loaded Session in construct method

PHP
<?php

declare(strict_types = 1);

namespace Vendor\Module\Model; 

use Magento\Backend\Model\Auth\Session;

class ClassName
{
    public function __construct(
      private Session $authSession
    ) {}
    
    public function getCurrentUser()
    {
        return $this->authSession->getUser();
        //get admin user name $this->authSession->getUser()->getUsername();
        //get current admin email $this->authSession->getUser()->getEmail();
    }
}

You can get more details about user with different methods like for get admin user name $this->authSession->getUser()->getUsername();

Here is code with Object Manager. We do not recommend to use Object Manager.

PHP
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$objectManager->get('Magento\Backend\Model\Auth\Session')->getUser()->getUsername();

I hope this blog is useful to get current admin user details in magento2. In case, I missed anything or need to add some more information, Don’t heisted to leave a comment in this blog, I’ll get back with some positive approach.

Keep loving ❤️ Keep inspiring 🤩 Keep liking 👍 No sharing 😄

10 Comments

  1. Ứng dụng xn88 có một bộ sưu tập slot game 3D vô cùng đa dạng và hấp dẫn. Những trò chơi này được thiết kế với đồ họa 3D sống động, âm thanh chân thực và các chủ đề phong phú từ phiêu lưu, cổ tích đến các câu chuyện thần thoại. TONY12-11A

  2. If you’re a Rummy fan, Rammy91 is worth checking out. Decent graphics, smooth gameplay, and a good community. Give it a whirl and see what you think: rammy91

  3. Yo, so I checked out 789clubios recently. The games are decent, and the signup process was smooth. Nothing crazy mind-blowing, but a solid choice if you’re looking for something new. Check it out here: 789clubios

  4. Gave 25phwin a spin last night. Nothing to write home about, but not bad either. Standard stuff, could be worse. Check it out: 25phwin

  5. Alright sbet77 peeps! Trying it out now. Looks pretty similar to other sites. Hope my luck gonna be increased this time! Just check it : sbet77

  6. Valorcasiono? Is that even a word? LOL. Anyway, been playing there for a bit now. It’s alright, nothing spectacular, but nothing terrible either. Just a standard casino site. Check it out: valorcasiono

Write A Comment