Offline login with already synced Realm


#1

Hello,

I have implemented Realm.asyncOpen and it is working fine, I’m able to receive and sync data to my server.
I just tested the scenario, when an already logged in user try to start my app without Internet connection and I got an error.

Only 1 user can access one time my app, so in the AppDelegate I check for SyncUser.all. There is the saved user, so I try to async open a realm with this stored user. I got error logs (Failed to connect to endpoint ‘127.0.0.1:9080’: Connection refused) - thats great, because the server is unreachable without internet.

The problem is that the Realm.asyncOpen call doesnt return anything in this scenario.
The “let realm = try! Realm(configuration: config)” returns, but i got an empty realm (realm.isEmpty = true).

Am i wrong? How can i open a synced realm offline?


#2

For anyone who interested:

I managed making it working with a workaround.
On first login or registration i’m using the Realm.openAsync method, but if the user already logged in then i’m using the “let realm = try! Realm(configuration: config)” way.

I will test it in the next few days, but it seems to be working right now.


#3

Perhaps you can help me - I just stumbled on the same problem.

The usual steps I use are to login the user and then use the returned SyncUser.configuration() to open the synced realm.

But if the internet is not available then do I just ignore the user.configuration() and use something else ?


#4

This is definitely possible to do with the beta RMP. I am just in the process of upgrading to Realm Cloud and encountered this issue. You could definitely open a synced realm offline and when the data connection is restored the data syncs.

Realm is offline first! In this situation basically the app is literally unusable if not connected to the internet. It makes no sense. I am sure realm doesn’t want us to manage an offline state. And I know this used to work fine in the beta.