问题描述
我正在尝试取消电子邮件与已关联电话号码和电子邮件的当前用户的链接。
我在这里做什么:
admin.auth().updateUser("user uid",{
email: null,password: null,})
.then(function(userRecord) {
// See the UserRecord reference doc for the contents of userRecord.
console.log('Successfully updated user',userRecord.toJSON());
})
.catch(function(error) {
console.log('Error removing email:',error);
});
但它返回错误 The email address is improperly formatted.
出于某种原因,只有当我删除电子邮件时才会发生这种情况,当我对电话执行相同操作时:
admin.auth().updateUser("user uid",{
phoneNumber: null,userRecord.toJSON());
})
.catch(function(error) {
console.log('Error removing phone number:',error);
});
以上代码有效,手机完美移除。但仅当我对电子邮件发生错误执行此操作时。
有什么我想念的吗?
解决方法
UpdateRequest#email
必须是 undefined
或有效的电子邮件。
UpdateRequest#password
必须是 undefined
或未散列的密码。
您也许可以使用:
admin.auth().updateUser("user uid",{
email: undefined,password: undefined,})
但您通常最好unlinking客户端上的 EmailAuthProvider 凭据。
firebase.auth().currentUser
.unlink(firebase.auth.EmailAuthProvider.PROVIDER_ID);