我正在 React 中使用 firebase 服务创建一个网络应用程序。我在登录屏幕上登录了 Google 和 Facebook,登录后用户可以选择链接他们的手机。我使用 Firebase Phone Auth为了这。用户已经签名,然后他们使用手机进行身份验证。我想将 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);
});
关于javascript - 在 Web 上的 Firebase 中将电话号码与 Facebook 和 Gmail 帐户相关联,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46659141/