有关firebase身份验证的问题,可通过电话号码进行身份验证。
我想知道是否可以将“电话提供商”与Google Auth Provider联系起来。在docs中没有明确提到它。
让我摸不着头脑的是 - Link Multiple Auth Provider文档谈论开始使用新的提供商(电话提供商)进行身份验证,以便链接到现有提供商(谷歌提供商),但随后停止调用FirebaseAuth.signInWithXXX
。
所以在理论上这将是这样的:
FirebaseAuth.signInWithXXX
,我们可以改为调用FirebaseUser.linkWithCredential(PhoneAuthCredential)
。所以我想知道如果没有明确登录PhoneAuthCredential
,电话号码验证是否完整?
您可以将PhoneAuthCredential链接到现有用户(在您的情况下是具有GoogleAuthProvider的用户)。
用Google登录用户后。然后你通过PhoneAuthProvider.getInstance().verifyPhoneNumber(phoneNumber, ...)
这将解决PhoneAuthCredential或验证ID。然后,您可以通过PhoneAuthProvider.getCredential
请求SMS代码并实例化PhoneAuthCredential。
然后,您可以将该凭证链接到currentUser:currentUser.linkWithCredential(phoneAuthCredential)
对于未来的角色和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);
});