1

I am working with Firebase Database and I want to store user data. I don't want for now to force user to login with Google account, so I added Firebase Anonymous auth. Authentication works fine, but when I uninstall and reinstall app the uid change every time. Exist some way to have uid generated by device? What is the purpose of this Google features if every time when user uninstall / reinstall application generate a new user? I know it also exist getProviderId() method but in this case is null.

This is my code:

public synchronized void getAnonymousUser(final OnAuthListener onAuthListener){

    if(onAuthListener == null){

        throw new IllegalArgumentException("listener cannot be null");
    }

    FirebaseUser currentUser = this.mAuth.getCurrentUser();
    if(currentUser != null){

        onAuthListener.getAnonymousUser(currentUser);
        return;
    }

    this.mAuth.signInAnonymously().addOnCompleteListener(new OnCompleteListener<AuthResult>() {
        @Override
        public void onComplete(@NonNull Task<AuthResult> task) {

            if(task.isSuccessful()){

                onAuthListener.getAnonymousUser(mAuth.getCurrentUser());
            }else {

                onAuthListener.onError(new Exception("signInAnonymously no user exception"));

            }

        }
    }).addOnFailureListener(new OnFailureListener() {
        @Override
        public void onFailure(@NonNull Exception e) {

            onAuthListener.onError(e);
        }
    });
}
KENdi
  • 7,576
  • 2
  • 16
  • 31
an_droid_dev
  • 1,136
  • 14
  • 18
  • 1
    Why are users going to be reinstalling your app? Firebase is generating a token for an anonymous authentication session. When you uninstall the app, you're clearing that data – OneCricketeer Aug 23 '17 at 13:44
  • 1
    Related: https://stackoverflow.com/questions/38236376/how-firebase-auth-uid-is-generated and https://stackoverflow.com/questions/2785485/is-there-a-unique-android-device-id – OneCricketeer Aug 23 '17 at 13:47
  • @cricket_007 if i will reset my phone for example – an_droid_dev Aug 23 '17 at 13:47
  • @cricket_007 thanks a lot! So it's not a correct way for what i want to do. – an_droid_dev Aug 23 '17 at 13:49
  • 1
    Makes sense, but then you lose all app data, not just your app. You don't have to use Google Auth. There's other providers – OneCricketeer Aug 23 '17 at 13:50

0 Answers0