如何检查用户何时在 Firebase 中进行了 phone 身份验证?

how to check when a user has phone authenticated in Firebase?

我有一个 Android 应用程序,用户在该应用程序中使用他们的 phone 号码注册,我使用 Firebase 在身份验证中存储他们的 phone 和他们的电子邮件,还有我我正在实时数据库中保存他们的 phone、他们的全名和电子邮件。实时数据库中的结构如下:

Auto-Generated ID 
+16505553434: "some@email.com"  
email:"some@email.com"  
first name: "First name"  
last name: "Last name" 
phone: "+16505553434"

用户注册并注销后,当他们再次尝试使用该应用程序时,我想:如果用户存在,我不想再次进行 phone 身份验证,这应该只发生一次,当他们注册如果用户存在于数据库中我只想输入他们的密码并登录。但问题是我如何检查用户是否phone在Firebase中注册。 如果用户已注册,我想显示输入密码的布局,而如果用户未注册,我想显示 OtpView 以便用户进行 phone 身份验证注册。 当用户注销时 FirebaseAuth.getInstance().getCurrentUser() 为空,因此我无法使用它。 如何检查用户是否已注册?

After the user has registered and signed out when they try to use the app again I want to: if the user exists I don't want to do phone authentication again this should happen only once when they register if the user exists in the database I want to just type their password and log in.

当用户使用 phone 号码进行身份验证时,不涉及密码。使用通过短信发送的验证码进行身份验证。因此,如果用户注销,他将无法简单地使用密码登录。他可以使用 phone 号码或任何其他提供商再次登录。

But the problem is how will I check if the user is phone registered in Firebase. If the user has registered I want to show a layout for the input password while if the user is not registered I want to show the OtpView so that the user to do phone authentication-registration.

您只需根据 phone 号码检查您的数据库,看看该用户是否已有帐户。像这样的查询可能会成功:

db.child("users").orderByChild("phoneNumber").equalTo("+16505553434");

如果有结果,说明该用户存在。为了能够让用户 "log-in with a password",您需要启用这种身份验证。您可以在 Firebase 控制台中非常轻松地完成此操作。但请记住,这是另一种身份验证类型,无法与第一种身份验证结合使用。检查有关 Authenticate with Firebase using Password-Based 的文档。因此,您可以使用 phone 号码 使用电子邮件和密码登录。您无法使用 phone 号码和密码登录。

When the user has signed out the FirebaseAuth.getInstance().getCurrentUser() is null so i cannot use that. What can I do to check if the user is registered or not?

当用户注销时,FirebaseUser 对象为空。您无法从该对象获取数据。只能查询数据库了。