Realm-cocoa: Calling SyncUser.current with multiple users exception vs. checking logged in status

Created on 23 May 2017  路  2Comments  路  Source: realm/realm-cocoa

Goals

Want to check to see if there is currently a user logged in but there are already several users logged in

Our documentation asserts that checking for a logged in user would be done by checking if SynUser.current != nil in the case of multiple active profiles this causes an exception.

Expected Results

SyncUser.current returns non- Nil for any condition where the are logged in users/profiles

Actual Results

Crash:

2017-05-22 14:35:33.557 RealmBingo[33458:4855586] *** Terminating app due to uncaught exception 'RLMException', reason: '+currentUser cannot be called if more that one valid, logged-in user exists.'

Steps to Reproduce

  • Have multiple users logged in
  • Call SyncUser.current

Code Sample

N/a

Version of Realm and Tooling

Realm framework version: RealmSwift 2.7.0

Realm Object Server version: 1.4.1

Xcode version: 8.2.3

iOS/OSX version: 10.12.5

Dependency manager + version: ?

T-Help

Most helpful comment

Hi, you can check your active users session this way (Swift code):

for user in SyncUser.all {
    debugPrint("user: \(user.key) - \(user.value)")
}

You will se something like this:

"user: a9c2de623e408422a3073b3276d54517 - <RLMSyncUser: 0x174247b90>"
"user: 0a12e0b10e217f228d4f313679f68c4d - <RLMSyncUser: 0x174246300>"

To call SyncUser.current without error you have to quit all other users session. For example:

for user in SyncUser.all {
    debugPrint("user: \(user.key) - \(user.value)")
    user.value.logOut()
}

All 2 comments

This is documented behavior:

The currentUser method will retrieve the current user, the last user who logged in and whose credentials have not expired. The method returns nil if no current user exists. An exception will be thrown if more than one logged-in user exists.

I feel this is correct as it might be misleading/undefined if there are more than one logged in users. You should use allUsers if your application supports such a scenario.

Hi, you can check your active users session this way (Swift code):

for user in SyncUser.all {
    debugPrint("user: \(user.key) - \(user.value)")
}

You will se something like this:

"user: a9c2de623e408422a3073b3276d54517 - <RLMSyncUser: 0x174247b90>"
"user: 0a12e0b10e217f228d4f313679f68c4d - <RLMSyncUser: 0x174246300>"

To call SyncUser.current without error you have to quit all other users session. For example:

for user in SyncUser.all {
    debugPrint("user: \(user.key) - \(user.value)")
    user.value.logOut()
}
Was this page helpful?
0 / 5 - 0 ratings