javascript - Firebase 当前用户更新电话号码
问题描述
我正在使用firebase Auth,我有一个包含两个字段名称和电话号码以及onsubmit 方法的表单,我想更新当前登录用户的电话号码和姓名。但它不会在提交时更新电话号码。仅成功更新用户的显示名。请检查下面的代码。onUpdateProfile 是表单提交函数。
<template>
<form @submit.prevent="onUpdateProfile">
<input type="text" v-model="profile.name" placeholder="Enter Your Name..." />
<input type="text" v-model="profile.phonenumber" placeholder="Enter Your phone..." />
<button type="submit">submit</button>
</form>
</template>
methods: {
onUpdateProfile() {
firebase.auth().onAuthStateChanged(user => {
if (user) {
//Getting Current User
let user = firebase.auth().currentUser;
user
.updateProfile({
displayName: this.profile.name,
phoneNumber: this.profile.phoneNumber
})
.then(() => {console.log('success})
.catch(error => {console.log(error});
//Updating User other details on submit
} else {
}
});
}
}
data() {
return {
profile: {
name: "",
phonenumber: ""
}
};
}
解决方案
您不能用于updateProfile
更新phoneNumber
. 您必须使用updatePhoneNumber
API,因为 Firebase 身份验证始终需要先验证电话号码,然后再将其保存给用户。
这类似于signInWithPhoneNumber
.
const phoneNumber = getPhoneNumberFromUserInput();
const appVerifier = new firebase.auth.RecaptchaVerifier(...);
firebase.auth().currentUser.updatePhoneNumber(phoneNumber, appVerifier)
.then((confirmationResult) => {
// SMS sent. Prompt user to type the code from the message, then complete
// verification by calling confirmationResult.confirm(code).
...
return confirmationResult.confirm(smsCode);
}).then((userCredential) => {
// Phone set on the user.
}).catch((error) => {
// Error occurred.
});
推荐阅读
- python - Python中的错误:列表索引超出范围
- angular - 测试无法识别模板驱动表单中的默认属性“form.invalid”
- mysql - Combining several similar queries
- python - 如何在 numpy 中累积用户定义的 ufunc?
- python - 如何在 Python 中替换单词。但是 "i" 到 "oraz" 和 "oraz" 到 "i"
- javascript - 使用 node.js 动态创建网页
- docker - 如何在 docker 中使用 heroku buildpacks
- reactjs - 在没有渲染方法的情况下访问 React Js 中的道具
- python - 将 Python 中的两个电子表格与 Pandas 合并,按“时间”列中最接近的“时间”,XX:XX:XX 格式的值
- mysql - 如果查询中的 COUNT-SELECT 不返回任何内容,则 MySQL 查询返回 false