Anonymous user in Realm Mobile Platform

Can I connect to the remote realm without having to log in?

In Swift, the only way to create a synchronous Realm is with the syncConfiguration property for Realm.Configuration . Is there a way to get an anonymous User so that everyone can connect to the remote realm?

+3
source share
2 answers

Can I connect to the remote realm without having to log in?

No, you always need to authenticate.

Is there a way to get an anonymous user so that someone can connect to the remote realm?

There is still no built-in anonymous login or anonymous user, as the Realm object server does not support account binding or direct merging of independently created Realms.

As a simple workaround, you can now rely on password-based authentication. Then you will need to create the user once and you will be able to hard-code these credentials in your application.

+2
source

Now it is possible in the cloud of clouds . Here's how I do it in Swift:

 if let user = SyncUser.current { //--== User available ==-- let config = Realm.Configuration(syncConfiguration: SyncConfiguration(user: user, realmURL: "...")) Realm.Configuration.defaultConfiguration = config let _ = try! Realm() }else{ //--== No User; Connect Anonymously ==-- let credentials = SyncCredentials.anonymous() SyncUser.logIn(with: credentials, server: "...") { user, error in DispatchQueue.main.async { if let user = user { let config = Realm.Configuration(syncConfiguration: SyncConfiguration(user: user, realmURL: "...")) Realm.Configuration.defaultConfiguration = config let _ = try! Realm() }else{ //Error... } } } } } 

Good luck

0
source

All Articles