我正在使用Firebase服务在React中创建一个Web应用程序。我在登录屏幕上登录了Google和Facebook,登录后用户可以选择链接他们的手机。为此,我使用Firebase Phone Auth。用户已签名,然后他们使用电话进行身份验证。我想将电话身份验证用户对象与Facebook/google帐户链接。
浏览文档时,我无法找到适合我的用例的解决方案。帮助将不胜感激。
这是一个简化的示例,如何使用不可见的 reCAPTCHA 将电话号码链接到 Google/Facebook 用户。
// Sign in the Google user first.
firebase.auth().signInWithPopup(new firebase.auth.GoogleAuthProvider())
.then(function(result) {
// Google user signed in. Check if phone number added.
if (!result.user.phoneNumber) {
// Ask user for phone number.
var phoneNumber = window.prompt('Provide your phone number');
// You also need to provide a button element signInButtonElement
// which the user would click to complete sign-in.
// Get recaptcha token. Let's use invisible recaptcha and hook to the button.
var appVerifier = new firebase.auth.RecaptchaVerifier(
signInButtonElement, {size: 'invisible'});
// This will wait for the button to be clicked the reCAPTCHA resolved.
return result.user.linkWithPhoneNumber(phoneNumber, appVerifier)
.then(function(confirmationResult) {
// Ask user to provide the SMS code.
var code = window.prompt('Provide your SMS code');
// Complete sign-in.
return confirmationResult.confirm(code);
})
}
})
.catch(function(error) {
// console.log(error);
});