【问题标题】:How can I update mobile number in firebase authentication using the updateProfie Method?如何使用 updateProfie 方法在 Firebase 身份验证中更新手机号码?
【发布时间】:2022-01-19 04:11:48
【问题描述】:

当用户注册时,我正在收集姓名、电子邮件、电话和密码。在 useFirebase 钩子中,我正在使用 firebase 的 updateProfile 方法更新 displayName。

该函数用于创建用户。

const userCreate = (name, email, password, phone, history) => {
    createUserWithEmailAndPassword(auth, email, password)
        .then((userCredential) => {
            //User Create after registration
            const newUser = { email, displayName: name, phoneNumber:phone };
           const uid = auth.currentUser.uid
            verifyEmail();
            updateProfile(auth.currentUser, {
                displayName: name, 
                phoneNumber:phone,
            })
                .then(() => {
                    console.log()
                })
                .catch((error) => {
                });
            history.replace('/');
        })
        .catch((error) => {
            console.log(error)
        })
}

注册后显示名称会更新。但我没有得到电话号码。我该怎么做?

【问题讨论】:

    标签: javascript firebase-authentication


    【解决方案1】:

    来自updating a user's profile上的文档:

    您可以使用updateProfile 方法更新用户的基本个人资料信息——用户的显示名称和个人资料照片 URL

    因此无法使用此功能更新用户的电话号码。原因是电话号码是用户登录凭据的一部分,因此需要通过专用方法(类似于他们的密码和电子邮件)进行更新。

    要更新用户的电话号码,请调用updatePhoneNumber 函数,如here 所示:

    // 'recaptcha-container' is the ID of an element in the DOM.
    const applicationVerifier = new RecaptchaVerifier('recaptcha-container');
    const provider = new PhoneAuthProvider(auth);
    const verificationId = await provider.verifyPhoneNumber('+16505550101', applicationVerifier);
    // Obtain the verificationCode from the user.
    const phoneCredential = PhoneAuthProvider.credential(verificationId, verificationCode);
    await updatePhoneNumber(user, phoneCredential);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-06-07
      • 1970-01-01
      • 2021-04-11
      • 2023-03-05
      相关资源
      最近更新 更多