Mwesigwa Ezra
Posts: 0
Joined: Fri Mar 27, 2015 7:05 am

How to access sessioToken from all pages

I have created a Modal in which i store a session Token successfully ,I was told in order to access it on other pages,i have to define it on the index page.I need help about how to exactly declare the sessionToken on index page and pass it on to a service request on another page. (kindly Use some sample Code) Thank you in advance

leven.steve
Posts: 0
Joined: Sun Mar 04, 2012 4:01 pm

How to access sessioToken from all pages

I do it like this - there may be a better way though!

Define a "Model" (did you mean Model rather than Modal?)

Image

Create a SCOPE variable on the index page like this:
Image

Assign to it like this when you have the token: code$scope.sessionToken = myToken;/code

And retrieve it like this: codevar token=$scope.sessionToken/code

Mwesigwa Ezra
Posts: 0
Joined: Fri Mar 27, 2015 7:05 am

How to access sessioToken from all pages

Let me give it a try.thank you Steve.i hope i really get it to work

Mwesigwa Ezra
Posts: 0
Joined: Fri Mar 27, 2015 7:05 am

How to access sessioToken from all pages

Hey Steve, i hope you are still there; In the service request, the session token is requested as X-Apperry-Session-Token. How exactly do u map my retrieved token to this field? Sorry am a newbie

leven.steve
Posts: 0
Joined: Sun Mar 04, 2012 4:01 pm

How to access sessioToken from all pages

Hi. For my database I have added some extra fields to the User collection. So after login I have a function called getUser to retrieve the whole user record. But this is the same procedure for any function that needs the session token. So if your function is called getData then in the code below replace getUser with getData.

Drag your service call to the function and in the "requestdata" mapping do it like this:

codevar requestData = {};
requestData = (function mapping9326($scope){
var requestData = {};
requestData.headers = Apperyio.EntityAPI('getUser.request.headers', undefined, true);
requestData.headers['X-Appery-Session-Token'] = $scope.sessionToken.id;

Code: Select all

 return requestData; 

})($scope);
Apperyio.get("getUser")(requestData).then(
function(success){ // success callback
/code

Just for your reference, on functions that need to pass parameters into the function call you can get access to those in a similar way:

coderequestData.params= Apperyio.EntityAPI('getUser_query_service.request.query', undefined, true);
requestData.params.sort="Name&quot
...
/code

Mwesigwa Ezra
Posts: 0
Joined: Fri Mar 27, 2015 7:05 am

How to access sessioToken from all pages

Wow,Wow,Wow. I owe u a big sandwich !

Return to “Issues”