【问题标题】:Delete a user by email in lieu of UID Firebase通过电子邮件代替 UID Firebase 删除用户
【发布时间】:2020-09-30 02:01:47
【问题描述】:

我在 Firebase 函数中成功删除了具有帐户 UID 的帐户,但是否可以通过电子邮件地址而不是其 UID 删除经过身份验证的帐户?

这就是我现在拥有的:

    admin.auth().getUserByEmail(userEmail).then(function(userRecord) {
            // See the UserRecord reference doc for the conteenter code herents of userRecord.
            console.log('Successfully fetched user data:', userRecord.toJSON());
        
            admin.auth().deleteUser(userRecord)
            
              .then(function

() {
            console.log('This is the ID being used!', userRecord);
    
            console.log('Successfully deleted user');
          })
          .catch(function(error) {
            console.log('This is the ID being used!', userRecord);
    
            console.log('Error deleting user:', error);
          });
    
      })
      .catch(function(error) {
       console.log('Error fetching user data:', error);
      });
    
    
        });

谢谢!

【问题讨论】:

    标签: node.js firebase firebase-authentication firebase-admin


    【解决方案1】:

    您可以在找到getUserByEmail() 的帐户后,使用deleteUser(uid) 删除用户帐户作为第二次操作。它返回的UserRecord 中有一个uid 字段。

    所以,而不是你现在正在做的事情:

    admin.auth().deleteUser(userRecord)
    

    改为这样做:

    admin.auth().deleteUser(userRecord.uid)
    

    【讨论】:

      【解决方案2】:

      admin sdk 没有按用户删除的方法,因此无法通过电子邮件删除用户。您可以使用您提到的方式。

      【讨论】:

        猜你喜欢
        • 2018-11-28
        • 1970-01-01
        • 2017-01-23
        • 1970-01-01
        • 2019-01-21
        • 2018-02-12
        • 1970-01-01
        • 1970-01-01
        • 2020-11-28
        相关资源
        最近更新 更多