如何使用 Firebase Admin Node JS SDK 从 Firebase 取消链接电子邮件

问题描述

我正在尝试取消电子邮件与已关联电话号码和电子邮件的当前用户链接

在这里做什么:

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);

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...