How to determine if the user signed in to Firebase with email and password or with google sign in?

前端 未结 4 2491
遥遥无期
遥遥无期 2021-02-10 04:30

I am working on a log in for a web application, and I have made it so the user can sign in manually with their email and password or by using a google sign in. Is there a way to

4条回答
  •  生来不讨喜
    2021-02-10 05:17

    @mjrdnk's answer is correct, but there is a caveat, a user could have multiple providers linked. So using firebase.auth().currentUser.providerData[0].providerId will always yield the same provider even when another linked provider was used to sign in. The most accurate way to determine the current provider used to sign is by inspecting the ID token's field: firebase.sign_in_provider.

提交回复
热议问题