How do I check if the session token is still active?

This forum contains topics that were moved from Get Satisfaction
Yurii Orishchuk
Posts: 0
Joined: Fri Feb 14, 2014 8:20 am

How do I check if the session token is still active?

Post by Yurii Orishchuk »

Hi Jack,

You need to use following syntax for invoking service datasource with parameters:

pre

var request = {
//Here you can specify header parameters
headers: {someHeader: "someValue"},
//Specify url string parameters. (works in all HTTP methods)
parameters: {"www": "aa"},
//Specify body parameters. (not supports by "GET" or "DELETE" methods, see RFC for details).
body: {"bdf": "123"}
};

checkService.execute(request);

/pre

Regards.

Mike Townsend
Posts: 0
Joined: Thu Dec 17, 2015 8:43 am

How do I check if the session token is still active?

Post by Mike Townsend »

Hi Yuri,

I wonder if you can help me please, I'm really struggling with validating a user is logged in, I have checked I have the correct
DatabaseID,
userID,
Token
As the user was only logged in seconds before - can you point out what is wrong with the following ajax please which i'm running through a jquery plugin ajaxq.

Using a similar approach it works fine to log users in but now I can't seem to validate them afterwards. I have read all the similar links on this but there must be a small adjustment i can make to the below to get it to work? Rather than a more complicated approach.

var ajaxRequest = {

url: encodeURIComponent("https://api.appery.io/rest/1/db/users/" +myUserID),

dataType: 'json',
cache: 'false',
type: 'get',
crossDomain: true,
headers: {
'X-Appery-Database-Id': myDatabaseID,
'X-Appery-Session-Token': mySessionToken
},
timeout: 10000,
success: checkValid_success,
error: checkValid_fail
};
$.ajaxq("myqueue", ajaxRequest);

Thanks for taking a look,
Mike

Mike Townsend
Posts: 0
Joined: Thu Dec 17, 2015 8:43 am

How do I check if the session token is still active?

Post by Mike Townsend »

Hi Yuri,

I've answered my own question minutes after posting it - even though I was struggling for hours on it - I've realised the above ajaxq approach works just fine if the url is not encoded. I'll leave the question there in case it is useful for others searching for solutions at any point (let me know if you want me to delete it).

I do have another question tho, I can't get the 'find' to work.

Can you give me some advice please on how I can get the ajaxq approach outlined above working using the REST API - FIND which is specified as this:

curl -X GET \
-H "X-Appery-Database-Id: " \
-H "X-Appery-Session-Token: " \
-G --data-urlencode 'where={"":""}' \
https://api.appery.io/rest/1/db/users

I suspect my problem is specifying the url properly, mine is specified as this:

var myUrl = encodeURIComponent("https://api.appery.io/rest/1/db/users...':'" +myUserID +"'}")

thanks in advance
Mike

Serhii Kulibaba
Posts: 147
Joined: Tue Aug 27, 2013 1:47 pm

How do I check if the session token is still active?

Post by Serhii Kulibaba »

Hello Mike,

Sory, you code is broken. Please use tag "pre" or "code" to wrap your code (https://getsatisfaction.com/some.html).
What are you trying to do? Do you need to get user's data? If so, please use request below for that: https://devcenter.appery.io/documenta...

AndyM
Posts: 0
Joined: Sun May 22, 2016 4:06 pm

How do I check if the session token is still active?

Post by AndyM »

I may be missing something but creating timers and calling a service to check if a login token has expired seems like an overkill..
I assume that if a service tries to use a token that expired it will get an error "invalid session token" or something like that
Why not just call User.login(..) at that point?
Am i overlooking something?
Thanks
Andy

Serhii Kulibaba
Posts: 147
Joined: Tue Aug 27, 2013 1:47 pm

How do I check if the session token is still active?

Post by Serhii Kulibaba »

Hello Andy,

You are talking about social login plugin, but the topic is about general functionality.

Post Reply