[英]FIREBASE phoneAuth ( LinkWithPhoneNumber ) . How to change a user's linked phone number later in Firebase Web. ( nodejs, Create-react-app )?
我在我的 create-react-app 项目中使用了 firebase。 出于注册目的,我使用firebaseAuth().createUserWithEmailAndPassword(email, password)
然后在注册后,我将他们的电话号码保存在 localStorage 中,然后使用此功能将它们重定向到 PhoneAuth 页面
export function PhnAuth(phone) {
window.recaptchaVerifier = new firebaseAuth.RecaptchaVerifier('recaptcha-container',{'size': 'small'});
return firebaseAuth().currentUser.linkWithPhoneNumber(phone, window.recaptchaVerifier)
.then(function (confirmationResult) {
window.confirmationResult = confirmationResult;
}).catch(function (error) {
})
}
在重新验证并完成所有操作后,我成功地将用户的电子邮件与他们的电话号码相关联。 但是稍后如何更新该电话号码? 我在文档中找不到有关更新链接电话号码的任何信息。
updatePhoneNumber
, User
对象上有一个updatePhoneNumber
方法。
请参阅参考文档和有关更新用户配置文件的文档。
请注意,为此您需要一个phoneCredential
,这意味着这必须是经过验证的电话号码。 查看如何在 firebase.auth (js, ts) 中更新用户电话号码。
如果您想在不验证的情况下更新用户的电话号码,可以通过 Admin SDK 完成。 有关此示例,请参阅如何在 NodeJS 中更新 Firebase 身份验证的电话号码?
我试图使用updatePhoneNumber API。 为了获得电话凭证,我认为您必须获得带有新电话号码的验证码。 因此,我必须使用带有新电话号码的verifyPhoneNumber API。 尝试这样做。
您需要取消当前手机的链接(provider.providerId === 'phone')
然后您可以链接一个新(provider.providerId === 'phone')
const currentUser = firebaseAuth().currentUser;
currentUser.unlink('phone').then(successCallback).catch(errorCallback)
要检查手机是否链接到当前用户,您需要检查提供商列表
const phoneProviders = currentUser.providerData.filter(
provider => provider.providerId === 'phone'
);
if (phoneProviders.length > 0) {
currentUser.unlink('phone').then(successCallback).catch(errorCallback);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.