appleboy/react-recaptcha

onRequestBegin config option

vijayst opened this issue · 1 comments

The new methods in BaseModel does not have an option to pass a token in the request header. I already have code for BaseModel - create which sets the session token in the request header.

BaseModel.addClassAction("create", function(attributes = {}) {
    API.requestHeaders[HEADER_SESSION_TOKEN] = authProvider.fetchToken();
    return API.request({
        method: "post",
        data: { resource: [attributes] },
        endpoint: this.urlRoot
    });
});

The above code will break if I upgrade mobx-model. To prevent too much of code rewrite, I propose adding another config option - onRequestBegin.

  config(options = {}) {
    Object.assign(this, pick(options, [
      'onRequestBegin',
      'onRequestError',
      'onRequestCompleted',
      'requestData',
      'requestHeaders',
      'urlRoot',
      'superagent'
    ]))
  },

onRequestBegin will be triggered before making the API call. With this change, I will be able to upgrade to the latest 0.32.

I am sorry for raising the issue in the wrong repo. I will close the issue.