Backendless Support
 
Answered

Force reload user

Hi,

how can I force reload current user?

I'm calling an hosted service (JAVA) that changes a property of user:

  1. ...
  2. BackendlessUser myUser = Backendless.UserService.findById(com.backendless.servercode.InvocationContext.getUserId());
  3. myUser.setProperty("someLimit",(limit-1));
  4. Backendless.UserService.update(myUser);
  5. ...

On my webpage (PHP), even if I reload the page, the attribute someLimit is not updated. Only if user logouts and logins again it updates object User properties.

Thanks

Leave a Comment

Comments (6)

photo
1

Hello!

Anyway, you should somehow update the BackendlessUser object on client side. You can make "findById" request, or relogin the user, or just change it manually inside client code without making a call to backendless.

However, I'm not sure why you need to update user through hosted service. For your case it would be more suitable to update the currentUser object directly on client side and send "update" request from it. This way you'll not be able to make extra request to update user object on client side.

regards,

Alex

photo
1

Well, that's just part part of the hosted service, basically user is authorized to do a complex action (that I prefer having it as service so that in future any client can benefit from it web/ios/android) and after that I decrease that limit field for the user.

I guess I can still do that in client side once the service returns success. But wont that make that if the same user is logged in with android he will still continue to see wrong value even after he refreshes the views?

Thanks for support

photo
1

Yes, it wouldn't be updated. SDK doesn't perform dynamic updating of retrieved objects. So, you need to update it through client code each time user refreshes views.

photo
1

Sorry for late reply, was just now trying to reload user on controller and UserService.php does not have any findById method.

Should I use Backendless::$Data->of('Users')->findById... ?

photo
1

Hi Mark,

that's the method called with:

  1. Backendless::$Data->of('Users')->findById()

right? I was just saying that:

  1. Backendless::$UserService->findById()

works for example with java, but not in php

Fatal error: Call to undefined method backendless\services\UserService::findById()

I may be looking at it entirely wrong, tho.

photo