如何确定用户是使用电子邮件和密码登录Firebase还是使用Google登录? [英] How to determine if the user signed in to Firebase with email and password or with google sign in?

本文介绍了如何确定用户是使用电子邮件和密码登录Firebase还是使用Google登录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为Web应用程序登录,我已经做了这样,用户可以使用他们的电子邮件和密码手动登录,或者使用谷歌登录。有没有办法确定他们使用的是哪种方法?最好使用Firebase身份验证状态更改功能。

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 determine which method they used? Preferably by using the Firebase authentication state change function.

`firebase.auth().onAuthStateChanged(firebaseUser => {....`

我知道您可以告诉他们在进入Firebase控制台日志时如何登录但是有没有办法使用JavaScript代码确定它?

I know you can tell how they signed in when you go into the Firebase console log but is there a way to determine it using JavaScript code?

使用 firebase.auth()。currentUser.providerData 以下内容:

When using firebase.auth().currentUser.providerData the following:

推荐答案

您可以使用currentUser来确定 https://firebase.google.com/docs/reference/js/firebase。 UserInfo

You can determine by using currentUser https://firebase.google.com/docs/reference/js/firebase.UserInfo

像这样:

firebase.auth()。 currentUser.providerData [0] .providerId

希望很有帮助。

这篇关于如何确定用户是使用电子邮件和密码登录Firebase还是使用Google登录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆