Firebase Auth - get provider ID
I had to JSON.stringify(currentUser.providerData)
in order to see how it's organized:
Stringify result
And i finally found the Auth Provider
like this:
currentUser.providerData[0].providerId
Cheers, gl with your code : )
Since a user can sign into their Firebase Authentication account with multiple providers, the top-level provider ID will now (usually) be Firebase
.
But the currentUser
has a providerData
property that provides information on the speciic providers. Looping over FIRAuth.auth()!.currentUser.providerData
will give you the FIRUserInfo.providerID
you're looking for.
See also this question about UIDs, which are in a similar situation: Firebase returns multiple IDs, Which is unique one?
Swift 4 solution:
if let providerData = Auth.auth().currentUser?.providerData {
for userInfo in providerData {
switch userInfo.providerID {
case "facebook.com":
print("user is signed in with facebook")
case "google.com":
print("user is signed in with google")
default:
print("user is signed in with \(userInfo.providerID)")
}
}
}