Backend Controller

How can I create a controller which is accessible only if admin is logged in? Or how can I determine if shop admin is logged in?

1 „Gefällt mir“

Hi Ivan,

because of the API first approch in Shopware 6, there is no controller which is only usable in the administration. The administration is a client for the admin API, so you could create a new controller and set its scope to this API. Have a look at this controller for example https://github.com/shopware/platform/blob/master/src/Core/Framework/Api/Controller/ApiController.php
Every route starting with „/api/v1/“ will be checked for authorization automatically. So you do not check this by yourself. If someone calls this route, whether it’s from the admin or from somewhere else, he must be authorized. It should not matter to you, if this is the shop admin or any other user, who has the rights to call your route.

Best regards from Schöppingen

cool Michael Telgmann

1 „Gefällt mir“

Hi Michael,

Thank you for your answer.

Hi @Michael_Telgmann , can you please add the new Link for the admin API? The given one brings me to the Homepage of the Developer Documentation.

You need this one? Admin API Guide - Shopware Developer