在iOS上,我们可以轻松地检索不同提供商ID cfr What is the full list of provider id's for firebase.UserInfo.providerId?
的常量。但是我看不到Android(Kotlin)的这些常量吗?
答案 0 :(得分:0)
我找到了:
import com.google.firebase.auth.EmailAuthProvider
import com.google.firebase.auth.FacebookAuthProvider
import com.google.firebase.auth.FirebaseUser
import com.google.firebase.auth.GoogleAuthProvider
fun FirebaseUser.loginType(): LoginType {
if (isAnonymous) {
return LoginType.Anonymous
}
Log.debug("providerId: $providerId")
Log.debug("EmailAuthProvider: ${EmailAuthProvider.PROVIDER_ID}")
Log.debug("GoogleAuthProvider: ${GoogleAuthProvider.PROVIDER_ID}")
Log.debug("FacebookAuthProvider: ${FacebookAuthProvider.PROVIDER_ID}")
loop@ for (userInfo in providerData) {
when (userInfo.providerId) {
EmailAuthProvider.PROVIDER_ID -> return LoginType.Email
GoogleAuthProvider.PROVIDER_ID -> return LoginType.Google
FacebookAuthProvider.PROVIDER_ID -> return LoginType.Facebook
else -> continue@loop
}
}
return LoginType.Unknown
}
fun FirebaseUser.loggedInWith(): String {
return when (loginType()) {
LoginType.Anonymous -> "Anonymous"
LoginType.Email -> email ?: "?"
LoginType.Facebook -> "Facebook"
LoginType.Google -> "Google"
LoginType.Unknown -> "???"
}
}