简体   繁体   中英

Firebase Authentication: How to know if account with Google or Facebook provider already exist?

Using FirebaseAuth signInWithCredential will create account using the provided credential from Google Sign In or Facebook Sign In if not yet exist but this is not always the desirable case. We need to control and check manually if the Google or Facebook credential is already used with Firebase Authentication. Is it possible to only check if the credential has already been used for account in the Firebase Auth, no sign in and specially no creation of account? If there is a method that creates user with the credential, there should be a dedicated signUpWithCredential which gives a better control and management.

I found an alternative, we can use fetchSignInMethodsForEmail this will not perform sign in which makes it better. We can provide the email address and get its list of provider via getSignInMethods . This saves a lot of time as we no longer need to create a Cloud Function just for the sake of checking.

The return list can be the following: EmailAuthProvider.PROVIDER_ID or "password" GoogleAuthProvider.PROVIDER_ID or "google.com" FacebookAuthProvider.PROVIDER_ID or "facebook.com"

If account does not exist then you'll get empty list.

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