User identities array empty even after login

I am using the Realm iOS SDK, and I would like to be able to know if the current user is logged in anonymously or not. However, when I access the current user using either app.currentUser or right after successfully logging in anonymously through the .success(let user) case, the identities property is always an empty array.

Is this a bug? How can I check if a user is logged in as an anonymous identity?

Hi @Elias_Heffan what version of Realm Cocoa are you using? I cannot reproduce this issue on the latest version of the SDK.

I’m using Carthage as my dependency manager, and it says I have version “v10.15.1”.

Could you update to 10.17.0 and see if the issue persists?

I have now updated to the latest version (10.17.0), but I am still getting the error. Here is the code I’m testing:

  func loginAsAnonymous(completion: @escaping (_ error: Error?) -> Void) {
    realmApp.login(credentials: Credentials.anonymous) { (result) in
      switch result {
      case .failure(let error):
        completion(error)
      case .success(let user):
        print("After login as anonymous, identities is: \(user.identities)")
        completion(nil)
      }
    }
  }

The print statement prints After login as anonymous, identities is: []

Hi @Elias_Heffan I still cannot reproduce this with the given code sample. Would you mind opening an issue for this on Issues · realm/realm-swift · GitHub and providing us with a sample app that can reproduce the issue?

1 Like

Hey so after some experimenting I was able to fix the issue by logging out and then logging back in as anonymous. I just had to do that one time, and now the identities array is working as expected and persists anonymous login over time.

While I did manage to fix the issue, this does seems like a bug, since previously it was showing that the user was logged in even though there were no identities listed in the identities array.

To avoid this bug in the future, for now should I always log out before trying to anonymously log in, even if there is no anonymous identity listed in the identities array?