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 😄

23 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

  7. Jilifish, huh? Sounds fishy in a good way! I like the look of the games they have. It is something new. Give it a shot if you’re feeling lucky. Dive in jilifish.

  8. Megapari Casino is a solid choice. I’ve tried quite a few platforms and this one stands out for its user-friendly design and a good selection of games. You should consider trying this for your chance to win something megaparicasino.

  9. How’s everyone doing at 0007win? I am thinking of signing up. Any big wins lately or any tips for a newbie? Good luck yall: 0007win

  10. 007gamepc seems like a hub for pc games. Is it a download site or an online gaming website? Thinking about trying it out. Check it out here 007gamepc

  11. Thinking about placing some bets on 22vipbet. Anyone have experience with this site? Fast payouts? Good odds? Let me know what you guys think: 22vipbet

  12. Kho game tại 188v me được phân loại theo chủ đề, nhà phát hành, mức cược và mức độ phổ biến – giúp bạn dễ dàng tìm được slot phù hợp với tâm trạng và ngân sách hiện tại. TONY02-11O

  13. I don’t think the title of your article matches the content lol. Just kidding, mainly because I had some doubts after reading the article.

  14. Thank you for your sharing. I am worried that I lack creative ideas. It is your article that makes me full of hope. Thank you. But, I have a question, can you help me?

Write A Comment