简体   繁体   English

如何将 Firebase 电话身份验证与电子邮件/密码身份验证联系起来?

[英]How Can I Link Firebase Phone Authentication with Email/Password Authentication?

I am trying to create an app in which after a user types his email/ password they are saved in the firebase then the user enters his phone number on which otp is sent and the user is logged in after verification.my problem is that when both of these steps are completed firebase is creating two separate accounts one with email other with the phone.我正在尝试创建一个应用程序,在用户输入他的电子邮件/密码后,它们会保存在 Firebase 中,然后用户输入发送 otp 的电话号码,用户在验证后登录。我的问题是这些步骤中的一部分已完成 firebase 正在创建两个单独的帐户,一个是电子邮件,另一个是手机。 Please Tell me how can I create a Single account with Both Email/Password and Phone.请告诉我如何使用电子邮件/密码和电话创建单个帐户。

Since you are using multiple Firebase authentication providers then you need to link them, so both phone and email will create on single account.由于您使用了多个 Firebase 身份验证提供程序,因此您需要将它们链接起来,因此电话和电子邮件都将在单个帐户上创建。

First you can get the credentials:首先,您可以获得凭据:

AuthCredential credential = EmailAuthProvider.getCredential(email, password);

then using linkwithCredentials() you will be able to link them:然后使用linkwithCredentials()您将能够链接它们:

mAuth.getCurrentUser().linkWithCredential(credential)
    .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
        @Override
        public void onComplete(@NonNull Task<AuthResult> task) {
            if (task.isSuccessful()) {
                Log.d(TAG, "linkWithCredential:success");
                FirebaseUser user = task.getResult().getUser();
                updateUI(user);
            } else {
                Log.w(TAG, "linkWithCredential:failure", task.getException());
                Toast.makeText(AnonymousAuthActivity.this, "Authentication failed.",
                        Toast.LENGTH_SHORT).show();
                updateUI(null);
            }

            // ...
        }
    });

more info here:更多信息在这里:

https://firebase.google.com/docs/auth/android/account-linking https://firebase.google.com/docs/auth/android/account-linking

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM