TransWikia.com

Get userid of the admin logged in magento 2 helper

Magento Asked by Fahad Bashir on February 12, 2021

Trying to get admin user id in Magento 2 helper,
in new at magento 2 any help will be appreciated.

One Answer

Below is a helper with a dependency and you can see within one of its function how the backend user id is read

<?php

namespace MbsBackendScreenHelper;

use MagentoFrameworkAppHelperAbstractHelper;
use MagentoFrameworkAppHelperContext;

class AdminUserReaderHelper extends AbstractHelper
{
    /**
     * @var MagentoBackendModelAuthSession
     */
    private $authSession;

    public function __construct(
        Context $context,
        MagentoBackendModelAuthSession $authSession
    ) {
        parent::__construct($context);
        $this->authSession = $authSession;
    }

    public function doSomethingWithMyAdminUserId()
    {
        ...
        if ($this->authSession->getUser() != null) {

            $adminUserId = $this->authSession->getUser()->getId();
        }
        
        ...
    }

}

Answered by Herve Tribouilloy on February 12, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP