Regarding user logout via REST API

Hi,
I am using REST API in AS3 programming.
When I logout user, logout is successful.
On successfull logout, I am clearing any local shared objects that store user token and other user data locally.
But when I login again I get this error {“code”:3064,“message”:“Not existing user token. Relogin user to update your user token”}.
If I quit the app and login again then login is successful.
I am wondering why I am getting following error?
Will be thankful of any guidance.
Below given is code I am using.
Thanks,
Tushar



public static var headers:Array = [
new URLRequestHeader('application-id', '2C268F11-55C9-113B-FF15-F291A39B4400'),
new URLRequestHeader('secret-key', <app secret key>),
//new URLRequestHeader('application-type', 'REST'),
new URLRequestHeader(Backendless.HDR_APP_TYPE, Backendless.APP_TYPE)
]

public function Backendless() { }



public static function Call(url: String, method: String, params: Object = null, success: Function = null, error: Function = null, token: String = null): void {
var ldr: URLLoader = new URLLoader();
var req: URLRequest = new URLRequest(url)

if (params != null) {
if (method == URLRequestMethod.GET) {
var vars: URLVariables = new URLVariables()
for (var p: String in params) {
vars[p] = params[p];
}
req.data = vars;
} else {
trace("request data:", JSON.stringify(params))
req.data = JSON.stringify(params)
}
}
//trace("method :: " + method);
req.method = method;
if(method != URLRequestMethod.DELETE){
req.contentType = Backendless.CONT_TYPE;
}
req.cacheResponse = true;
req.useCache = true;
req.requestHeaders = headers

if (token != null) {
req.requestHeaders.push(new URLRequestHeader('user-token', token))
}

var parseData:Function = function(e:Event):void{
var data:Object
trace('loader data: ', e.target.data)
if (e.target.data == '' || e.target.data is Boolean) {
trace('loader data is empty or boolean')
success(e.target.data)
}else{
trace('loader data seems JSON string')
data = JSON.parse(e.target.data)

for(var s:String in data){
trace(s, '::', data)
}
}
if(data != null){
if(data.hasOwnProperty("message") && data.hasOwnProperty("code")){
trace('loader data is error message')
if(error != null){
error(data["message"])
}
}else{
trace('loader data is success object')
success(data)
}
}
}



if (success != null) {
ldr.addEventListener(Event.COMPLETE, parseData, false, 0, true)
}



ldr.addEventListener(IOErrorEvent.IO_ERROR, function(ev:IOErrorEvent):void{
trace('IO error', ev.text)
}, false, 0, true)



// Debug -----------------> 
ldr.addEventListener(HTTPStatusEvent.HTTP_RESPONSE_STATUS, function (e:HTTPStatusEvent) {
trace(e.status)
for each(var r:URLRequestHeader in e.responseHeaders){
trace("request header:: ", r.name, " : ", r.value)
}
}, false, 0, true)
// <-----------------------
ldr.load(req)
}



public static function SignOut(userToken: String, success: Function = null, error: Function = null): void {
var url: String ='https://api.backendless.com/' + 'v1' + '/users/' + 'logout'
Backendless.Call(url, URLRequestMethod.GET, null, success, error, userToken);
}















After little modification, i am able to login and I get new token which I save locally.

I user new token to query data table, but now i get same above error {“code”:3064,“message”:“Not existing user token. Relogin user to update your user token”}.
I have done this check 4-5 times, every times it gives same error.

Please advice what could have gone wrong.

Thanks
Tushar

Hi

Waiting about this.
Please reply.

Tushar

Hi Tushar!

We are working on this issue.
Regards,
Kate.

Hi Kate,

Thanks for updating.

Glad to know that it is from server side and not our coding problem.
Now I can work on other stuff. :slight_smile:
Will be waiting for solution to this.

Thanks,
Tushar

Hi Tushar,

Here is the pure working example, you can test it in your Terminal with curl (this is my test application and test user):
Login request:

curl \
-H application-id:BBDAAC19-D8E0-3AAE-FF03-90203AAC7F00 \
-H secret-key:4E70E147-789E-DA3C-FFBD-D0AA9C849500 \
-H application-type:REST \
-H Content-Type:application/json \
-d '{"login":"sam@email.com","password":"qwerty"}' \
-X POST [url=https://api.backendless.com/v1/users/login]https://api.backendless.com/v1/users/login[/url]

In response I get:

{
"lastLogin":1452762466276,
"created":1452762176000,
"name":null,
"___class":"Users",
"user-token":"BAD52CFC-4A15-AD14-FF54-1FF4AE323A00",
"ownerId":null,
"updated":null,
"objectId":"C2C0188C-A862-FD34-FF01-320521178900",
"email":"sam@email.com",
"__meta":"{\"relationRemovalIds\":{},\"selectedProperties\":[\"__updated__meta\",\"password\",\"created\",\"name\",\"___class\",\"ownerId\",\"updated\",\"objectId\",\"email\"],\"relatedObjects\":{}}"}

From where I take user-token value and use it in logout request:

curl \
-H application-id:BBDAAC19-D8E0-3AAE-FF03-90203AAC7F00 \
-H secret-key:4E70E147-789E-DA3C-FFBD-D0AA9C849500 \
-H application-type:REST \
-H user-token:BAD52CFC-4A15-AD14-FF54-1FF4AE323A00 \
-X GET [url=https://api.backendless.com/v1/users/logout]https://api.backendless.com/v1/users/logout[/url]

Now my user is logged out and I can login again successfully and get a new user-token.

How is this example different from what you do? Could you please provide your REST requests in the same form here?

Hi Sergey,

Thanks for you efforts, but the issue was with my coding.
By mistake previous token was also stored in a variable in some other class which was causing this issue.
Sorry guys!

Regards,
Tushar