0

I wrote my app so that when it registers, it creates the user on Firebase using email, a username and the password.

However, when the user tries to login, I can't figure out how to fetch their username from Firebase.

public void tokenAuthentication() {
    fireBase.authWithCustomToken(token, new Firebase.AuthResultHandler() {
        @Override
        public void onAuthenticated(AuthData authData) {
            mAuthData = authData;
            final String userId = authData.getUid();
            SharedPreferences.Editor peditor = myPrefs.edit();
            peditor.putString("auth_token", authData.getToken());
            peditor.putString("UID", userId);
            peditor.commit();
            Log.i("LoginActivity","SuccessAuth: UID: "+authData.getUid());
            peditor.commit();
            movetoMain();
        }

        @Override
        public void onAuthenticationError(FirebaseError firebaseError) {
            makeToast(firebaseError.toString());
        }
    });
}

I tried using their onDataChanged method, but since I'm not changing data, I'm just trying to fetch, it didnt work.

Any ideas? If more information is needed, please let me know.

Thank you

Reaz Murshed
  • 23,691
  • 13
  • 78
  • 98
leofontes
  • 898
  • 4
  • 16
  • 40
  • There is documentation for querying/fetching data, no? What else have you tried? – OneCricketeer Apr 24 '16 at 01:25
  • There isnt, the only documentation for querying/fetching is this: https://www.firebase.com/docs/android/guide/retrieving-data.html Which only serves for dataChange, not a simple Query. – leofontes Apr 24 '16 at 01:26
  • I just read that page, and it seems like `addListenerForSingleValueEvent` should work. The `onDataChanged` is just the name of the method – OneCricketeer Apr 24 '16 at 01:32
  • 2
    Please edit your question to include how you create the user. Without seeing how you create the user, it's impossible to answer how (or even if) you can read the data back. – Frank van Puffelen Apr 24 '16 at 02:35
  • I think you've problem with understanding how to use the authenticated `Uid` to retrieve the data from firebase database. Is that the case? – Reaz Murshed Apr 24 '16 at 13:51

0 Answers0