A
A
Alexander2021-09-03 18:47:37
1C-Bitrix
Alexander, 2021-09-03 18:47:37

How to use ajax module interface for not authorized user?

Is it even possible?

Keep getting:

errors: [{message: "Необходимо авторизоваться на сайте", code: "invalid_authentication", customData: null}]
0: {message: "Необходимо авторизоваться на сайте", code: "invalid_authentication", customData: null}
code: "invalid_authentication"
customData: null
message: "Необходимо авторизоваться на сайте"


Including even on staff:
BX.ajax.runAction("currency.format.get", {data: {currencyId: currency}})


Is it somehow possible to use ajax for an unauthorized user?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2021-09-03
Madzhugin @Suntechnic

I asked myself - I answer myself:
A set of prefilters, own for each action.
Apparently, there is some way to configure the action, through the annotation, but I did not dig that deep.
In practice, it is enough to remove the default authorization filter from an action that should work for unauthorized users. You can do this in, for example, in the init method of your controller:

protected function init()
  {
        parent::init();
        
        $this->setActionConfig('apply',[
            '-prefilters' => [
                    '\Bitrix\Main\Engine\ActionFilter\Authentication'
                ]
            ]);
    
  }

    
    public function applyAction()
    {

Here we say that \Bitrix\Main\Engine\ActionFilter\Authentication should be removed from apply controller prefilters

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question