realm / realm-object-server

Tracking of issues related to the Realm Object Server and other general issues not related to the specific SDK's
https://realm.io
293 stars 42 forks source link

SyncUser.logOut is not valid any longer (Realm Android 5.10) #422

Closed zeeshanz closed 4 years ago

zeeshanz commented 5 years ago

The Doc says to use SyncUser.logOut but it is not valid any longer. https://docs.realm.io/sync/using-synced-realms/users

You cannot get the current user either since SyncUser user = SyncUser.current() fails with an exception.

So at this point there really are no instructions how to logout a user and how to deal with this error:

Current user is not valid if more that one valid, logged-in user exists.

pavelpoley commented 5 years ago

Same happen

nirinchev commented 5 years ago

What is the error message you're getting when calling user.logOut?

pavelpoley commented 5 years ago

in my case

I am call

SyncUser.current().logOut()

but when logging in (With different account) again this exception is thrown.

java.lang.IllegalStateException: Current user is not valid if more that one valid, logged-in user exists.

This exception only happen when i am logging in with different account, for example i was logged in with some account then do log out then logging in with different account.(not happen with same account)

I tried to restart activity but same result.

I am using Google authentication with JWT.

nirinchev commented 5 years ago

The problem is not with logOut() but rather with the fact you're calling SyncUser.current(). What you can do is to either logout the current user before logging in the new one or use SyncUser.allLoggedIn() to get all logged in users and log out everyone except the new user.

pavelpoley commented 5 years ago

Correct, the exception thrown on SyncUser.current(). But this is the problem that i am call SyncUser.current().logOut() before logging in with new user.

nirinchev commented 5 years ago

@bmunkholm this is Java issue and I don't really have much knowledge to debug further.

cmelchior commented 5 years ago

This exception should only be thrown if multiple users are logged in, but it is unclear why this has happened. Instead of calling SyncUser.current() you can iterate over all known users by calling SyncUser.users() instead. This should give you an idea about what the underlying cause might be.

bmunkholm commented 4 years ago

@pavelpoley @zeeshanz Did any of you try above?

bmunkholm commented 4 years ago

Closing due to no response. Please reopen when/if you can provide more details.