0
votes

In my sencha touch 2.1, after successful login a token is sent back from service which has to be stored and used with all future service calls. Since I am dealing with remote web service so all the stores use JsonP proxy to fetch data which is why I want to add the token to all such calls. Since JsonP doesn't support headers I am planning to add this token as url param but I am not sure how to do this for all JsonP calls originating from app.

A similar question for AJAX calls was found
Send user details (session token) within every AJAX requests (Sencha Touch 2)

but since JsonP does not support 'beforerequest' event and headers, I am stuck.

Is there any other event I can listen/intercept to add this url param? is there a way to write base proxy class which has this functionality? Please share some examples if you know how to do this.

1

1 Answers

0
votes

Ok, I found a way that worked for me.

I extended JsonP proxy and in buildUrl method I appended cached token, and now I an using this proxy in all my stores. Here is the code:

Ext.define('myshop.proxy.CustomJsonpProxy', {
  extend: 'Ext.data.proxy.JsonP',
  alias: 'proxy.customjsonpproxy',
  buildUrl: function(request) {
    var me      = this,
        url     = me.callParent(arguments);
    if(!Ext.isEmpty(loggedInUserToken)){
        url = Ext.urlAppend(url, "token="+loggedInUserToken);
    }
    return url;
  }
});

Please share if you know of other better ways.