FIREBASE phoneAuth (LinkWithPhoneNumber)。稍后如何在 Firebase Web 中更改用户的链接 phone 号码。 (nodejs,Create-react-app)?

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)

然后在 SignUp 之后我将他们的电话号码保存在 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) {
    })
}

在重新验证并完成所有操作后,我成功地将用户的电子邮件与其电话号码相关联。但是以后如何更新那个 phoneNumber 呢?我在文档中找不到任何关于更新链接电话号码的信息。

User 对象上有一个用于该目的的 updatePhoneNumber 方法。

参见reference docs and the documentation on updating a user's profile

请注意,为此您需要 phoneCredential,这意味着这必须是经过验证的 phone 号码。参见

如果您想在不验证的情况下更新用户的 phone 号码,可以通过 Admin SDK 完成。有关此示例,请参阅

您需要取消link当前的phone(provider.providerId === 'phone') 然后你可以link一个新的

    const currentUser = firebaseAuth().currentUser;

    currentUser.unlink('phone').then(successCallback).catch(errorCallback)

要检查 phone 是否已 linked 给当前用户,您需要检查提供商列表

    const phoneProviders = currentUser.providerData.filter(
      provider => provider.providerId === 'phone'
    );
    if (phoneProviders.length > 0) {
      currentUser.unlink('phone').then(successCallback).catch(errorCallback);
    }