简体   繁体   中英

How to get UID and add user information with Firebase email/password authentication

I am using firebase Email/password authentication for both signup and sign in. However during the Sign up process I would like to get the user UID and use that to create a new database in firebase with other user information like Name and phonenumber. I know its easier to get the UID with a login process, however is there a way to do this with signup, assuming sign up has been successful. I am using android studio.

You can get the user information from the task returned by the completion listener:

    mAuth.createUserWithEmailAndPassword(email, password)
            .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
                @Override
                public void onComplete(@NonNull Task<AuthResult> task) {
                    Log.d(TAG, "createUserWithEmail:onComplete:" + task.isSuccessful());

                    if (task.isSuccessful()) {
                        FirebaseUser user = task.getResult().getUser();
                        Log.d(TAG, "onComplete: uid=" + user.getUid());
                    }
                }
            });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM