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);
}
});
}