Magento 2 Contains Multiple Users for the admin panel to access different sections of the functionality based on their User Roles.
You can see User Roles in the admin panel by clicking on the left navigation System -> Permissions -> User Roles.
You can get the current logged user id in Magento 2 by calling Class.
Magento\Authorization\Model\UserContextInterface
<?php namespace Rbj\UserRole\Model; use Magento\Authorization\Model\UserContextInterface; class GetUserRole { /** * @var UserContextInterface */ protected $userContext; public function __construct( UserContextInterface $userContext, ) { $this->userContext = $userContext; } public function getUserRoleId() { $roleId = $this->userContext->getUserId(); return $roleId; } }
You need to call the getUserRoleId() function from the above class to get the Current User role id.
The return value will be the User Id of the current User.