Current user not synced with Backendless server

Hi,

In my app I’m retrieving information from the current user frequently so it is important for me that the user’s information is synced with that from Users table that is stored on Backendless servers.

The problem is when some user property changes when the app is not running. Then when the app is started, the user’s property didn’t change locally even though it is changed on the server.

Backendless version: BackendlessSwift v6.2.10

Steps to reproduce the issue:

Let’s presume that the Users table has column ‘isPremium’ which is boolean.
And let’s presume that the current value of that property is true. Also, let’s presume
that user will never login or logout, he will always be logged in - only user token validation will be performed.

Expected behavior:

  1. Start the app
  2. Validate user token
  3. Print current user’s ‘isPremium’ property (prints true)
  4. Exit the app (without logout)
  5. Change the user’s ‘isPremium’ property to false in Backendless console
  6. Start the app
  7. Validate user token
  8. Print current user’s ‘isPremium’ property (prints false)

Actual behavior:

  1. Start the app
  2. Validate user token
  3. Print current user’s ‘isPremium’ property (prints true)
  4. Exit the app (without logout)
  5. Change the user’s ‘isPremium’ property to false in Backendless console
  6. Start the app
  7. Validate user token
  8. Print current user’s ‘isPremium’ property (prints true)

Hello @Hrvoje_Ditrih ,

what if you will retrieve user information from the server after user token validation?
Will this solve your issue?

Of course it would. But that is not the point. I would expect that Backendless SDK keeps track of that.

SDK should not have to do such updates in the background on its own - for this purpose there are the necessary tools that you can use. You can also use the real-time feature to update data in real time.

Regards,
Stanislaw

Why is there a method of getting the current user if it’s not up to date with server? You should then at least document that when getting the current user that it may not be most up to date version and that you would need to fetch the user from database itself, but then it begs the question why is there even a method of getting the current user if i have to do it myself manually.

For eg. there are also time when I rely on the current user in API Services on CloudCode. How do I know then if I’m getting the most up-to-date version of the current user? If I knew that getting the current user does not give the actual user information I would’t have used it altogether.

I think that every Backendless customer expects such functionality from that method, same as me. So you should either fix it or document it properly.

Sorry, I didn’t realize you are using getCurrentUser method, it is not mentioned in the behavior description. Now I understood you.

Sure, this is wrong behavior and getCurrentUser method should always return the user’s object up to date.
I have created an internal ticket in order to make it work properly.
You can reference it by its internal ID - BKNDLSS-24311.

Regards,
Stanislaw

Hello @Hrvoje_Ditrih,

The currentUser behaviour is changed in v6.3.0. Could you please update and verify whether it works as expected now?

Regards,
Olha

Hi @olhadanylova,

Getting the current user after the user token validation now fetches the up-to-date user information.
Would be great if it did that any time that the current user method is called, not just after connecting to Backendless.

Thanks for the suggestion. We will discuss this ability with a team.

Hello,

We won’t change the currentUser behaviour. However, you can implement this logic

fetches the up-to-date user information
any time that the current user method is called

using the findById() method.

Regards,
Olha

Hi @Hrvoje_Ditrih ,

To get the latest user at any time, we’d recommend using the objectId property from the user object returned by getCurrentUser and then using the findById() method in the Data service API you can retrieve the latest user object from the database.

Regards,
Mark