简体   繁体   中英

Firebase Authentication using email and google

I'm using firebase in Android Studio with kotlin.

I want to know whether login account is email-register account or google social account.

As I know, if FirebaseAuth.getInstance().currentUser.providerId is "google.com", user used google social login.

And if providerId is "password", user used email register with firebase.

But only I can get "firebase" from providerId.

How can I solve it?

It it is neccessary for making login function.

I can get only "firebase" from providerId.

According to the API documentation , getProviderId() (or just providerId for Kotlin) will always return FirebaseAuthProvider#PROVIDER_ID (which is equal to "firebase" ).

If you want to determine which authentication channel was used to get this Firebase ID Token, you need to use getProviderData() which contains the UserInfo objects returned from the social logins.

val auth = FirebaseAuth.getInstance();
val hasLinkedGoogleUser = auth.providerData.any{ it.providerId == GoogleAuthProvider.PROVIDER_ID }

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