Firebase Auth: Get users by email or phone number

后端 未结 4 2141
独厮守ぢ
独厮守ぢ 2021-01-16 18:24

I am building an Android App where I am using different ways for the user to register himself, like Email/Password, Phone, Google, Facebook, Twitter. I also

4条回答
  •  失恋的感觉
    2021-01-16 18:51

    I presume you are using firebase for your authentication, since you tagged firebase in your question. Firebase authentication usually fetches the user's name during authentication so you can get those details during sign up, add them to your database and assign a unique id to each user. You can then create a friends node for each user on the system where their friends' ids will be stored. An example of sign up /sign in is shown below:

    FirebaseAuth mAuth = FirebaseAuth.getInstance();
    mAuth.signInWithCredential(credential)
                    .addOnCompleteListener(this, new OnCompleteListener() {
                        @Override
                        public void onComplete(@NonNull Task task) {
                            if (task.isSuccessful()) {
                                // Sign in success, get available information
    
                                final FirebaseUser user = mAuth.getCurrentUser();
                                if (user != null) {
                                    if (user.getEmail() != null) {
                                        //since various methods are available, you may want to use names
                                        String name = user.getDisplayName();
                                        //if email exists, you can try this
                                        user.getEmail();
                                        //otherwise, this is sure to exist but you may want to tell your users 
                                        //to complete their profiles later
                                        user.getUid()
                                    }
                                } else {
                                    //Notify user
                                }
                            } else {
                                //The whole process failed
    
                            }
    
                        }
                    });
    

提交回复
热议问题