【问题标题】:Firebase phone authentication : once phone entered check if there is a user with that phone in usersFirebase 电话身份验证:一旦电话进入,检查用户中是否有使用该电话的用户
【发布时间】:2018-08-01 07:58:22
【问题描述】:

大家好,我正在尝试为登录进行电话身份验证,并在用户注册时使用电子邮件和密码进行注册,它将电子邮件和密码存储在 firebase 默认用户中,并添加带有其他用户信息的新 firebase 对象电话, 汽车信息 , 姓名

现在登录时,用户输入他们的手机,但是(但是)我不希望任何之前未注册的用户登录并获得身份验证我想检查是否存在输入的用户电话号码在数据库中

我不能使用 UID,因为用户还没有登录怎么办?

【问题讨论】:

  • 你有代码吗?请将其添加到您的问题中

标签: android firebase authentication


【解决方案1】:

Osama,在注册过程中,您需要使用电话 (+xxxxxxxxxx) 对用户进行身份验证。

您需要立即执行的下一个步骤是将此手机与电子邮件和密码相关联。

假设用户现在已经退出。他想重新登录。

1) 例如他在电话号码视图中,他输入了他的电话号码(+xxxxxxxxxx),在他正确输入短信代码后,您需要检查此电话是否链接到任何其他电子邮件密码凭据

在 FIRAuth auth signInWithCredential using phone 中,您可以检查 FIRAdditionalUserInfo 中的“phone”和“password”是否已经链接到密码并提示他登录。

2) 例如他选择登录(它应该只要求他的电子邮件和密码)

更新:

private void signInWithPhoneAuthCredential(PhoneAuthCredential credential) {
mAuth.signInWithCredential(credential)
        .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
            @Override
            public void onComplete(@NonNull Task<AuthResult> task) {
                if (task.isSuccessful()) {
                    // Sign in success, update UI with the signed-in user's information
                    Log.d(TAG, "signInWithCredential:success");

                    FirebaseUser user = task.getResult().getUser();
                    // ...get the user.providerData and FIRAdditionalUserInfo providerID "password"

                } else {
                    // Sign in failed, display a message and update the UI
                    Log.w(TAG, "signInWithCredential:failure", task.getException());
                    if (task.getException() instanceof FirebaseAuthInvalidCredentialsException) {
                        // The verification code entered was invalid
                    }
                }
            }
        });
}

【讨论】:

  • 谢谢你,但你能给我一个例子来说明如何实现你所说的我将不胜感激
  • @Osama 更新了代码和一些提示。建议你在 FirebaseUser user = task.getResult().getUser();并检查这些关键字里面的值 "// ...获取 user.providerData 和 FIRAdditionalUserInfo providerID "password""
猜你喜欢
  • 1970-01-01
  • 2019-02-22
  • 2020-11-08
  • 2020-08-18
  • 2021-07-13
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多