使用Firebase Phone Auth验证电话号码是否需要完全登录?

问题描述 投票:1回答:2

有关firebase身份验证的问题,可通过电话号码进行身份验证。

我想知道是否可以将“电话提供商”与Google Auth Provider联系起来。在docs中没有明确提到它。

让我摸不着头脑的是 - Link Multiple Auth Provider文档谈论开始使用新的提供商(电话提供商)进行身份验证,以便链接到现有提供商(谷歌提供商),但随后停止调用FirebaseAuth.signInWithXXX

所以在理论上这将是这样的:

  1. 用户通过谷歌(谷歌idp提供商)登录
  2. 用户启动电话身份验证(电话号码提供商) - 并获取短信。
  3. SMS在某些情况下应触发自动验证,或者他从短信息中输入6位数代码
  4. 但基于帐户链接的文档,而不是在这里调用FirebaseAuth.signInWithXXX,我们可以改为调用FirebaseUser.linkWithCredential(PhoneAuthCredential)

所以我想知道如果没有明确登录PhoneAuthCredential,电话号码验证是否完整?

firebase-authentication firebaseui
2个回答
4
投票

您可以将PhoneAuthCredential链接到现有用户(在您的情况下是具有GoogleAuthProvider的用户)。

用Google登录用户后。然后你通过PhoneAuthProvider.getInstance().verifyPhoneNumber(phoneNumber, ...)这将解决PhoneAuthCredential或验证ID。然后,您可以通过PhoneAuthProvider.getCredential请求SMS代码并实例化PhoneAuthCredential。

然后,您可以将该凭证链接到currentUser:currentUser.linkWithCredential(phoneAuthCredential)


0
投票

对于未来的角色和JavaScript用户来说,这是一种实现这一目标的方法:

const phoneCreds = firebase.auth.PhoneAuthProvider.credential(this.windowRef.confirmationResult.verificationId, phoneConfirmCode);

        firebase.auth().currentUser.linkAndRetrieveDataWithCredential(phoneCreds)
            .then(response => {
                console.log('*********', response);
                // Manage other firestore data
            })
            .catch((error) => {
                console.log('error', error);
            });
© www.soinside.com 2019 - 2024. All rights reserved.