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.getRefreshToken() is package-local, shouldn't it be public?

See original GitHub issue

Goal

What do you want to achieve?

Login with a previous non-expired session.

Expected Results

Successful login and synchronization

Actual Results

Cannot login with previous token since SyncUser does not expose getRefreshToken() anymore.

I managed to find some code that uses reflection to access this method, but I don’t believe this should be the way.

Steps code to reproduce

SyncCredentials creds = SyncCredentials.usernamePassword("xxxxxxxxxx", "xxxxxxxxxxx");

SyncUser.Callback callback = new SyncUser.Callback<SyncUser>() {
    @Override
    public void onSuccess(SyncUser user) {
        SyncConfiguration build = new SyncConfiguration.Builder(user, REALM_URL)
                .waitForInitialRemoteData()
                .modules(new CnaRealmModule())
                .build();
        Realm.setDefaultConfiguration(build);

        Token refreshToken = getRefreshToken(user);

//      prefs.realmRefreshToken()

    }

    public void onError(ObjectServerError error) {
        String errorMsg;
        switch (error.getErrorCode()) {
            case UNKNOWN_ACCOUNT:
                errorMsg = "Account does not exists.";
                break;
            case INVALID_CREDENTIALS:
                errorMsg = "User name and password does not match";
                break;
            default:
                errorMsg = error.toString();
        }
        Log.d(TAG, errorMsg);
        Toast.makeText(LoginActivity.this, errorMsg, Toast.LENGTH_SHORT).show();
    }
};
SyncUser.loginAsync(creds, REALM_AUTH_URL, callback);

Version of Realm and tooling

Realm version(s): 4.2.0

Realm sync feature enabled: yes

Android Studio version: 3.1.0

Which Android version and device: -

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
mdumraufcommented, Nov 29, 2017

Worked like charm. Thanks! Documentation should be updated mentioning this.

0reactions
Maxxancommented, Nov 29, 2017

The SyncUser is serialized to disk and read next time you ask for it, so it will not be null if you don’t log out that user.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Where to store the refresh token on the Client? - Stack Overflow
Access token and refresh token shouldn't be stored in the local/session storage, because they are not a place for any sensitive data. Hence...
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