How to check in frontend whether a backend user (administrator) is logged in?

Hi guys.

I am building an extension for magento 2. I want to check in controller in frontend that admin is logged or not. I try to research but I don’t find a way to do that. Please help me.

Thanks

A browsers sends the Magento 2 backend cookies to the Magento 2 server only when the browser requests the backend pages (because of the cookies path):

So if a Magento 2 server is requested for a frontend page, the server does not receive the backend cookies from the browser and unable to authenticate (identificate) whether a user is a backend user or not.

A solution would be to add a plugin to the backend authentication method, and set the domain-wide path (/) for the backend cookies.

1 Like