gpt4 book ai didi

javascript - 如何在firebase.auth(js,ts)中更新用户电话号码

转载 作者:行者123 更新时间:2023-12-03 07:20:55 26 4
gpt4 key购买 nike

如何在 firebase.auth 中更新用于身份验证的用户电话号码?

Firebase 作为方法给出:

updatePhoneNumber(phoneCredential)

但是我们需要给 电话凭证 .
此凭证接受对象:
  interface AuthCredential {
providerId: string;
signInMethod: string;
}

这个 中必须有什么电话凭证 ,我尝试发送
providerId: 'phone';
signInMethod: 'phone';

这是行不通的;(

最佳答案

使用当前用户/登录帐户更新电话号码的解决方案。万一这对任何人都有帮助。

问题:
假设您有一个当前登录的帐户,其中包含任意数量的单个/合并帐户,并且他们想要更新他们的号码。他们会怎么做。

解决方案:
以下是 Auth for Web/JS 方法,您的目标平台将存在等效方法。

function updateProfilePhoneNumber() {
//country code plus your phone number excluding leading 0 if exists.
var phoneNumber = "+447xxxxxxxxx"; //you could provide a prompt/modal or other field in your UX to replace this phone number.

// let phoneNumber = "+441234567890"; //testing number, ideally you should set this in your firebase auth settings
// var verificationCode = "123456";

// Turn off phone auth app verification.
// firebase.auth().settings.appVerificationDisabledForTesting = true;

// This will render a fake reCAPTCHA as appVerificationDisabledForTesting is true.
// This will resolve after rendering without app verification.
var appVerifier = new firebase.auth.RecaptchaVerifier(
"recaptcha-container",
{
size: "invisible"
}
);

var provider = new firebase.auth.PhoneAuthProvider();
provider.verifyPhoneNumber(phoneNumber, appVerifier)
.then(function (verificationId) {
var verificationCode = window.prompt('Please enter the verification ' +
'code that was sent to your mobile device.');
phoneCredential = firebase.auth.PhoneAuthProvider.credential(verificationId, verificationCode);
user.currentUser.updatePhoneNumber(phoneCredential);
})
.then((result) => {
// Phone credential now linked to current user.
// User now can sign in with new phone upon logging out.
console.log(result);
})
.catch((error) => {
// Error occurred.
console.log(error);
});
}

很高兴在这里得到纠正。

关于javascript - 如何在firebase.auth(js,ts)中更新用户电话号码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49942415/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com