The situtationis is as follows:
the user logins and then updates his profile with this code:
user.name = "dan";
Backendless.UserService.update(user);
it works perfect.
if the user exits and initiates the app again (the stayloggedin parameter is set to true) this code is executed
Backendless.initApp(APPLICATION_ID, SECRET_KEY, VERSION);
if(Backendless.UserService.getCurrentUser()!== null)
{
user = Backendless.UserService.getCurrentUser();
}
and then tries to update his profile with the code mentioned at the beggining, the following eror shows up:
Only Backendless.User accepted (at backendless.min.js:45)
i’ve printed the user object in the first case and second case. They only differ in the property user-token, which the first one doesn’t have. I’ve tried deleting the property with
delete user['user-token'];
Both users (the one before reload and afterwards) are the same. But i still get the same error.
Finally i have tried also asynchronous:
Backendless.UserService.update( user, new Backendless.Async( userUpdated, gotError ) );
it does not work either.
I suspect it has something to to with the Backendless.UserService.getCurrentUser() after the call to Backendless.initApp
Could you please try this:
Run your code with this script instead of backendless.min.js:
http://api.backendless.com/sdk/js/latest/backendless.js
Take screenshots in Chrome’s Network tab of what the browser sends for the update request in both cases. Please post the screenshots here.
Thanks,
Mark
There are no outgoing messages for the error call. The error is now on line 1329
thanks,
Nicolas
What is the line number where the second call fails? Can you catch the stack trace for it in Chrome?
Sure,
Uncaught Error: Only Backendless.User accepted backendless.js:1329
UserService.update backendless.js:1329
Based on the code it looks like the object in the update() call is not an instance of Backendless.User. We will have to look into it. It appears the object is not retrieved from LocalCache properly
Alright,
Thanks for your asistance
Best regards
Nicolas
Hi Mark,
Is the fix for this scheduled for the next release? If so, when will it be?
Best regards,
Nicolas
Well, there is a big problem. The stay logged in option is not working.
According to the new documentation the way to validate if a user token is valid is by using
var userTokenIsValid = Backendless.UserService.isValidLogin();
Upon reentering the app i get the token is true, yet the user variable remains as undefined. Where should i load the user from?
By the way, there is a error in the documentation.
at the beginning it says
Backendless.UserService.getCurrentUser();
but then it says
Backendless.UserService.CurrentUser();
The first one is the correct one, albeit it doesn’t work
Nicolas,
The script works. The problem is in the doc. I will update it in a minute.
See this (and try the code there):
http://jsfiddle.net/hutwj1mx/
Please let me know once you try it so I can delete the app (the app-id and secret key are exposed…)
I will update the doc in a minute.
Regards,
Mark
I spoke to soon. Now it recovers the user object properly from the local storage, however it does not allow me to update the user. The same problem as the beginning of the thread:
Error: Only Backendless.User accepted
You’re right. I played with it some more and the object from the local cache is returned untyped, which is the root cause of the problem. I will escalate this problem and it will be fixed asap.
I apologize it is taking us so long…
Nicolas,
Here’s how it is going to work:
Backendless.UserService.isValidLogin() - will return true or false whether the current user-token is valid. If it is valid, then the user does not need to re-login and your app can proceed without it.
Backendless.UserService.loggedInUser() - IF you set stayLoggedIn to true, this method will return user's objectId. We decided NOT to store user object on the client. You would need to retrieve it with an API call (see below)
Backendless.Data.of( Backendless.User ).findById( objectId ) - retrieves Backendless.User object for the given user id. The argument is the result of method from (2).
The updated script will be on the site some time tomorrow.
Regards,
Mark
Mark, Sorry for the late answer.
Yes, finally, it works perfectly
Cheers!
Hi Nicolas,
I am so glad to hear that. Thanks for confirming.
Cheers,
Mark
While updating a user profile, which was working previously, i get this error:
PUT https://api.backendless.com/v1/users/63BD4B15-809E-6A1F-XXXXXXXXXX 504 (Gateway Time-out) <html>
<head><title>504 Gateway Time-out</title></head>
<body bgcolor="white">
<center><h1>504 Gateway Time-out</h1></center>
<hr><center>nginx/1.4.2</center>
</body>
</html>