4

Can I connect to a remote Realm without having to login?

In Swift, the only way to create a synchronizable Realm is through the syncConfiguration property of a Realm.Configuration. Is there a method for getting an anonymous User so that anyone can connect to the remote Realm?

EpicPandaForce
  • 79,669
  • 27
  • 256
  • 428
chrisamanse
  • 4,289
  • 1
  • 25
  • 32

2 Answers2

3

Can I connect to a remote Realm without having to login?

No, you always need to be authenticated.

Is there a method for getting an anonymous User so that anyone can connect to the remote Realm?

Yes, via SyncCredentials.anonymous().

solidcell
  • 7,639
  • 4
  • 40
  • 59
marius
  • 7,766
  • 18
  • 30
2

This is now possible in Realm Cloud. Here's how I am doing 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!

Clifton Labrum
  • 13,053
  • 9
  • 65
  • 128