Search code examples
javafirebasefirebase-authenticationfirebase-security

Can i set a custom uid in firebase anonymous auth with java?


I am authenticating anonymously to access firebase but I would like the self-assigned UID to be according to a standard that I have defined, then I leave the anonymous authentication code I use:

auth.signInAnonymously()
        .addOnCompleteListener(task -> {
            if (task.isSuccessful()) {


                mUsername = idChat.substring(0, 10);
                id = task.getResult()
                        .getUser()
                        .getUid();
                isLoggedIn = true;
                mPhotoUrl = "";
                initAdapter();
            }
        })
        .addOnFailureListener(task -> displayError(task.getMessage()));

Solution

  • No, you cannot. You can use Firebase Anonymous Authentication to create and use temporary anonymous accounts to authenticate with Firebase. Note, that if an anonymous user decides to sign up to your app later, you can link their sign-in credentials to the anonymous account so that they can continue to work with their protected data in future sessions.

    Users are identifiable by the same Firebase user ID regardless of the authentication provider they used to sign in (Anonymous Authentication, User/Password, Google account, Facebook account and so on).

    So the custom id is generated by Firebase and there is no possibility to set a custom uid as in your terms.