Page 1 of 1

Easy way to retrieve sessionToken

Posted: Wed Dec 09, 2015 8:14 pm
by Nicklas

Hello!
I've tried to find out how to get the sessionToken when im in a new page.

This is what I mean:
I have two pages: Login and Menu.

Everything works perfect when I click "Log in!" button. After mapping the username and password, I navigate to a page (menu). (Mapping = Order 1, navigate = Order 2).
What now?
Do I have to Set the sessionToken in a storage variable? Or is it possible to retrieve the sessionToken in another way?


Easy way to retrieve sessionToken

Posted: Wed Dec 09, 2015 10:26 pm
by Jack Bua

On the success event of the login the service responds with the session token. Grabbing it then and placing it in local storage is the best method that I have found. In fact, it is the only method I know of.

So after you map the user info into a user storage variable (I am assuming mapping if from the inputs on the page), map the session token into a storage variable. Do this session token mapping the the success event of the login service.


Easy way to retrieve sessionToken

Posted: Thu Dec 10, 2015 11:05 am
by Serhii Kulibaba

Hello Nicklas,

The best way is using storage variables for that. Please clarify, what exactly doen't fit you in that case?


Easy way to retrieve sessionToken

Posted: Thu Dec 10, 2015 11:16 am
by Nicklas

Thank you for answeres!

If we do an example:

After success login, I put the sessionToken in a storage variable.

Lets say I want the sessionToken be shown in a label on the next page (in this case "menu").
How do I do that?


Easy way to retrieve sessionToken

Posted: Thu Dec 10, 2015 5:58 pm
by Jack Bua

Assuming that you want it to go into the label when the page shows:
1 in the events section of the platform, select your page, select the page show event, select the action of mapping
2 check the box for storage on the right and expand the page components on the left until you find your label.
3 click and drag the session storage variable over to the Text property of the label.
4 save and test.

BONUS:

The console is your best friend when it comes to testing.

https://devcenter.appery.io/documenta...

If you would like, after step 3, do this:
click the green icon that says "JS" in it. Now you can add JS to this mapping. type

console. log("Session Token is: " + value); // This adds the session token and some text to the console

return value; //this assigns the value of the storage variable to the mapping destination.

Now, when you get to that page, you can open your console and see your session token. I log the session token to the console on every successful login so that I can grab a fresh token every time I need one when trying something in a service test.


Easy way to retrieve sessionToken

Posted: Thu Dec 10, 2015 7:20 pm
by Nicklas

Thank you! I found it out with your help!:)