PDA

View Full Version : How can I modify a schema header



Crushin
12 Feb 2015, 8:41 PM
I am attempting to write an application using 5.1 and Parse.com.

When a user logs into the app, they are given a sessionToken. In order to use the REST API, I need to add that sessionToken to the model schema header. How can I modify the model schema header in run-time?

Currently my model schema looks like the code below. I have sessionToken as a global javascript var. Obviously that isn't working.




schema: {
id: 'users',
namespace: 'top.model',
proxy: {
type: 'rest',
url: 'https://api.parse.com/1/users/',
useDefaultXhrHeader: false,
withCredentials: false,
headers: {
'X-Parse-Application-Id': "xxxxxxxx",
'X-Parse-REST-API-Key': 'xxxxxx',
'X-Parse-Session-Token': sessionToken,
'Content-Type': 'application/json'
},
reader: {
type: 'json',
rootProperty: 'results',
transform: function( data ) {
return data.results ? data.results : {results:data};
}
},
writer: {
type: 'json',
writeRecordId: false
}
}
}

Crushin
12 Feb 2015, 9:04 PM
I found the answer here: http://www.sencha.com/forum/showthread.php?285824-Model-s-Schema-%28and-Proxy%29-must-be-hardcoded Basically I do a model.setProxy() before I create an model instances.