question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

SyncUser.currentUser is not cleared on log out

See original GitHub issue

Logging out doesn’t seem to clear the current user. This makes it very hard to switch users. I had to manually remove the signed out user from the SyncManager user store to get sign out/switch user to work as expected. Are you supposed to have to do this manually? In the realm tasks app, the current user is ignored when switching users, which seems like a workaround too.

I am using full synchronziation for my realm if that helps

Code Sample

SyncManager.addAuthenticationListener(object:AuthenticationListener{
    override fun loggedOut(user: SyncUser?) {
        SyncManager.removeAuthenticationListener(this)
        user?.let {
              //Without this line SyncUser.currentUser() will not return null even though the user has bee 
              // signed out
            SyncManager.getUserStore().remove(user.identity, user.authenticationUrl.toString())
        }
        signOutFromMyOwnAuthSystemAndRestartApp()
    }
    override fun loggedIn(user: SyncUser?) {}
})
SyncUser.current().logOut()

Version of Realm and tooling

Realm version(s): 5.2.0

Realm sync feature enabled: yes

Android Studio version: 3.1.3

Which Android version and device: Nexus 5x

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:17 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
bmunkholmcommented, Nov 30, 2021

Closing as this is related to legacy sync.

0reactions
siperssocommented, Dec 2, 2019

As stater earlier. SyncUser.getCurrent returns null if you call it directly after log out, which is probably what the unit test is covering. But when you start the next activity it won’t be null anymore.

In my case, the workaround works good enough, which is why it is hard to prioritize producing a repro case. But without a workaround this can lead to corrupted realms, so it is severe. I’ll see if I can make time for producing a sample, but I can’t make any promises. Already spent a lot of time on this issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Realm logOut Current user is not valid - Stack Overflow
Currently this is working only after activity restart public void logOut() { Map<String, SyncUser> all = SyncUser.all(); for (Map.
Read more >
SyncUser (Realm 5.3.1) - MongoDB
public static SyncUser current(). Returns the current user that is logged in and still valid. A user is invalidated when he/she logs out...
Read more >
Logout - Auth0
Log users out of Auth0 by clearing the Single Sign-on (SSO) cookie. ... It is not necessary to log the users out of...
Read more >
How to Log Out User Sessions in SharePoint Online?
Requirement: Force Log Off all sessions of a user, as he lost his mobile device, which is logged-in with SharePoint Online sites.
Read more >
Chapter 8: Log in, log out | Ruby on Rails Tutorial (3rd Ed.)
boolean method, which we'll now define. A user is logged in if there is a current user in the session, i.e., if current_user...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found