This is a migrated thread and some comments may be shown as answers.

Datasource beforesend context?

2 Answers 75 Views
This is a migrated thread and some comments may be shown as answers.
Maximiliano
Top achievements
Rank 1
Veteran
Maximiliano asked on 15 Apr 2019, 06:51 AM

i'm using kendovue for an application that i'm creating, the thing is that i must send the bearer token on each request. but i'm unable to pass it to the server as the function assigned to the beforesend event has the context of the request and not the vue component.

 

dataSource: new kendo.data.DataSource({
      page: 1,
      pageSize: 20,
      serverPaging: true,
      transport: {
        read: {
          url: "/api/users/list",
          dataType: "json",
          beforeSend: function (req) {
            req.setRequestHeader('Authorization', 'bearer ' + this.$auth.token());
          }
        }
      },
      schema: {
        total: function (data) {
          return data.Data.Total;
        },
        data: function (data) {
          let d = data.Items;
          return d;
        }
      }
    }),


can someone point me on the right direction?
regards.

2 Answers, 1 is accepted

Sort by
0
Accepted
Veselin Tsvetanov
Telerik team
answered on 17 Apr 2019, 06:23 AM
Hi Maximiliano,

To get the Vue context you will have to handle the beforeSend action in an external method defined in the Vue component instance:
methods: {
    onBeforeSend: function(req) {
      let component = this;
      debugger;
      //req.setRequestHeader('Authorization', 'bearer ' + this.$auth.token());
    }
}

Here you will find a small sample implementing the above suggestion.

Regards,
Veselin Tsvetanov
Progress Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Maximiliano
Top achievements
Rank 1
Veteran
answered on 17 Apr 2019, 04:02 PM
gracias!
Asked by
Maximiliano
Top achievements
Rank 1
Veteran
Answers by
Veselin Tsvetanov
Telerik team
Maximiliano
Top achievements
Rank 1
Veteran
Share this question
or