SyncUser.current multiple values crash

cloud

#1

I moved to a new Realm in the cloud.

For authentication, I am using Google with a token (jwt)

When I try to log in using the token for my user, my app crashes when I call SyncUser.current because Realm is finding the old user from the old realm that I moved from - as well as the user on the current Realm.

It is here where things go bad…

+ (RLMSyncUser *)currentUser {
    NSArray *allUsers = [[RLMSyncManager sharedManager] _allUsers];
    if (allUsers.count > 1) {
        @throw RLMException(@"+currentUser cannot be called if more that one valid, logged-in user exists.");
    }
    return allUsers.firstObject;
}

If I print out the users info, I see this value:

CURRENT REALM:
Printing description of (*( (std::__1::string *)0x107e403c8)):
(std::__1::string) m_server_url = "https://multilayered-foo-bar.us1a.cloud.realm.io"

OLD REALM:
Printing description of (*( (std::__1::string *)0x10883c648)):
(std::__1::string) m_server_url = "https://intuitive-plastic-table.us1.cloud.realm.io"

How can I force the user from the “old” Realm to be logged out, or in some way make them go away?

Thanks!


#2

I was able to fix the crash by uninstalling the app from the device and then re-installing it.

Definitely not ideal, but I can get past this issue.


#3

You can get all users by calling SyncUser.all and then call user.logOut() for each user you don’t want to keep around.