Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Firebase如何链接使用phoneNumber创建的帐户_Javascript_Reactjs_Firebase_Firebase Authentication - Fatal编程技术网

Javascript Firebase如何链接使用phoneNumber创建的帐户

Javascript Firebase如何链接使用phoneNumber创建的帐户,javascript,reactjs,firebase,firebase-authentication,Javascript,Reactjs,Firebase,Firebase Authentication,✅ 我可以让用户使用verifyPhoneNumber和updatecurrentUser.updatePhoneNumber ❌ 我的问题是,当我允许通过电话登录时,新用户尝试使用电话号码登录,就会自动创建一个帐户 如果我需要将号码与电子邮件帐户关联,上述方法将返回已在使用的凭证错误 Firebase在其应用程序中推荐以下方法 所以我一起做了这个linkWithCredential但是,signInWithCredential返回一个结果result.credential=null // Si

✅ 我可以让用户使用
verifyPhoneNumber
和update
currentUser.updatePhoneNumber

❌ 我的问题是,当我允许通过电话登录时,新用户尝试使用电话号码登录,就会自动创建一个帐户

如果我需要将号码与电子邮件帐户关联,上述方法将返回
已在使用的凭证
错误

Firebase在其应用程序中推荐以下方法

所以我一起做了这个
linkWithCredential
但是,signInWithCredential返回一个结果
result.credential=null

// Sign in user with the account you want to link to
auth.signInWithCredential(credential).then(function(result) {
  console.log("Sign In Success", result);
  var currentUser = result.user;

  return prevUser.linkWithCredential(result.credential) //this line doesn't work.
    .then(function(linkResult) {

      return auth.signInWithCredential(linkResult.credential);
    })
}).catch(function(error) {

  console.log("Sign In Error", error);

});
由于result.credential=null,我无法继续使用LinkWithCredential

我也尝试了
linkWithPhoneNumber
,但它返回了一个验证ID,我仍然无法合并该帐户

❓我可以知道你们是如何将电话号码帐户与其他帐户(Facebook/google/email)合并的吗

const confirmationResult=wait firebase.auth().currentUser.linkWithPhoneNumber(phoneNumber,recaptcha);
//在此处提示您的用户输入他们通过sms收到的代码
确认结果。确认(代码);
您有一个用户通过用户名/密码、facebook谷歌等登录。。。 行吗


由于您不会从电话链接中获得验证ID,而是一个

如果您想将现有帐户与电话号码链接,您可以使用
linkWithPhoneNumber
。基本上,在用户登录(比如谷歌)后,您可以检索用户信息,然后将该凭证和电话号码链接起来。我找到了一个与您的问题类似的详细答案

您可以使用身份验证提供程序链接:

async sendSmsVerification() {
// 'recaptcha-container' is the ID of an element in the DOM.
const applicationVerifier = new firebase.auth.RecaptchaVerifier('recaptcha-container')
const provider = new firebase.auth.PhoneAuthProvider()

const confirmationResult: firebase.auth.ConfirmationResult = await this.userData.linkWithPhoneNumber('+1nnnnn', applicationVerifier)
.catch(error => error)

const verificationCode = window.prompt('Please enter the verification ' +
  'code that was sent to your mobile device.')

  const res = await confirmationResult.confirm(verificationCode)
  .catch(error => error)
  console.log('res', res)

applicationVerifier.clear()

return res  }
res将告诉您该操作是否成功、用户输入的代码是否错误或电话号码是否已在使用。 作为奖励,用户现在还可以使用电话号码登录

您可以在此处找到更多详细信息:

这就是您要找的吗?请看我的问题我也尝试了使用PhoneNumber链接,但它返回了一个验证ID,我仍然无法合并该帐户。它不会返回凭证,但我会为您提供奖励以供尝试。我也尝试了linkWithPhoneNumber,但它会返回验证ID,我仍然无法合并帐户。如果电话号码已经是注册帐户(SMS登录),则此操作无效
async sendSmsVerification() {
// 'recaptcha-container' is the ID of an element in the DOM.
const applicationVerifier = new firebase.auth.RecaptchaVerifier('recaptcha-container')
const provider = new firebase.auth.PhoneAuthProvider()

const confirmationResult: firebase.auth.ConfirmationResult = await this.userData.linkWithPhoneNumber('+1nnnnn', applicationVerifier)
.catch(error => error)

const verificationCode = window.prompt('Please enter the verification ' +
  'code that was sent to your mobile device.')

  const res = await confirmationResult.confirm(verificationCode)
  .catch(error => error)
  console.log('res', res)

applicationVerifier.clear()

return res  }