SyncUser.current() is null even after running logInAsync() with correct credentials


I set up my credentials and then I call logInAsync. However, it never enters the onSuccess or onError functions. The error is also inconsistent; it doesn’t happen everytime. The error occurs when I try to set config = … because I am using a null pointer.

SyncCredentials credentials = SyncCredentials.usernamePassword(email, password, true);
        RealmAsyncTask task = SyncUser.logInAsync(credentials, authURL, new SyncUser.Callback<SyncUser>() {
            public void onSuccess(SyncUser result) {
                user = result;

            public void onError(ObjectServerError error) {
String url = "realms://";
        config = SyncUser.current().createConfiguration(url).build();


Answered here -