如何检查用户何时在Firebase中对电话进行了身份验证? [英] how to check when a user has phone authenticated in Firebase?

本文介绍了如何检查用户何时在Firebase中对电话进行了身份验证?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Android应用程序,其中用户使用其电话号码注册在该应用程序中,我正在使用Firebase在Authentication中存储其电话和电子邮件,还将我的电话,其全名和他们的电子邮件.实时数据库的结构如下:

I have an Android app where users are registered in the app with their phone number, I am using Firebase to store in Authentication their phone and their email and also I am saving in the Realtime Database their phone, their full name, and their email. The structure in the Realtime Database is as follows:

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

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

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. 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. 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?

推荐答案

当用户注册并注销后再次尝试使用该应用程序时,我要:如果该用户存在,则我不想再次进行电话身份验证,如果该用户存在,则仅当他们注册时才发生一次我只想输入他们的密码并登录.

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.

通过电话号码对用户进行身份验证时,不涉及密码.使用通过SMS发送的验证码进行身份验证.因此,如果用户退出,则无法简单地使用密码登录.他可以使用电话号码或其他任何提供商再次登录.

When a user is authenticated with the phone number, there is no password involved. The authentication is made using the verification code that is sent via SMS. So if the user signs out, there is no way he can simply log-in using a password. He can log-in again using the phone number or any other provider.

但是问题是我将如何检查用户是否在Firebase中注册了电话.如果用户已经注册,我想显示输入密码的布局,而如果用户没有注册,我想显示 OtpView ,以便用户进行电话身份验证注册.

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.

您可以简单地根据电话号码检查数据库,以查看用户是否已经有一个帐户.这样的查询可以解决问题:

You can simply check your database against the phone number to see if the user already has an account. A query like this might do the trick:

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

如果获得结果,则表示用户存在.为了能够使用户使用密码登录",您需要启用这种身份验证.您可以在Firebase控制台中非常轻松地完成此操作.但是请记住,这是另一种身份验证,不能与第一种身份验证结合使用.查看有关使用基于密码的Firebase进行身份验证的文档.因此,您可以使用电话号码登录电子邮件和密码.您无法使用电话号码和密码登录.

If you get a result, it means that the users exist. To be able to let the user "log-in with a password", you need to enable this kind of authentication. You can do it very easily in the Firebase console. But bear in mind that this is another type of authentication that cannot be combined with the first one. Check the docs regarding Authenticate with Firebase using Password-Based. So you can either sign-in with the phone number or with the email and password. You cannot sign-in with a phone number and password.

当用户注销FirebaseAuth.getInstance().getCurrentUser()为null时,我将无法使用它.如何检查用户是否已注册?

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 对象为null.您无法从该对象获取数据.您只需查询数据库即可.

When the user signs out, the FirebaseUser object is null. There is no way you can get data from that object. All you can do it to query the database.

这篇关于如何检查用户何时在Firebase中对电话进行了身份验证?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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