Check User type is customer or guest in Magento 2.

You can check the current user type using programmatically to customers or guests.

The difference between Customer and Guest user type is resource access. Customer User type has anonymous or self permission are allowed where later one access only Resources with anonymous permission.

Magento store the constant user type value in Magento\Authorization\Model\UserContextInterface.

Method calls from the template or any PHP class to check specific user type value,

If the result of the method  is 3, the user type is customer and return value 4 used to the guest.

Output:
int or null

Leave a Reply