update current user after a change from business logic

What is the right way to update the currentUser? Say one of the properties on the user was updated from outside the client, how can the client fetch an updated model?

Hi Gal,
It is a good question. There is no special method for fetching the current user from the server in SDK.
We will add some possibility to do this in nearest future.
Now, as a workaround you can make next custom function:

function fetchCurUser() {
  var curUserObjectId = Backendless.LocalCache.get("current-user-id");
  if( curUserObjectId ) {
    return Backendless.Data.of( Backendless.User ).findById( curUserObjectId )
  }
  
  return Promise.resolve(null);
}

And then use this function in next way:

fetchCurUser().then(function(curUser) {
  ...
})

I am not sure that you use JS on the client side of your app but I think the main thought is clear.
Also, please pay attention that I use Promise in my example. So if you take this code to your project make sure that you do enablePromises.

Regards Ilya

Thanks Ilya, two questions:

  1. Why do you use Backendless.LocalCache as opposed to Backendless.userService.currentUser?

  2. After a successful callback, is it safe to set the currentUser to the model in the response?

Hi Gal,
Firstly, please, could you clarify what programming language do you use for your client side?

Regards Ilya

I am working in objective c

Hello Gal,

Please, check this code:

BackendlessUser *currentUser = [backendless.userService currentUser];
id <IDataStore> dataStore = [backendless.persistenceService of:[BackendlessUser class]];
BackendlessUser *user = [dataStore findID:currentUser.objectId];
[user setName:@"XXX"];
[dataStore save:user];

Regards, Olga

Perfect. Thank you guys.